Tuesday 19 January 2010

A Cool but pointless script

Ok, Powershell may be the best thing to happen to windows (and other) administrators since the slicing of bread… or more likely since the mmc console.  But for everything useful you can find a completely pointless task for fun… this is what I have be spending a few hours doing recently.

I had seen some ones script to make a Powershell Christmas tree about a month back and thought that was quite cool, then having started this blog I created a twitter account to go along side.  I was happy with the little bird type icon that you get as a default Profile Picture but my wife told me I had to do something more interesting.  I didn’t want to have the standard Powershell picture that most Powershell tweeters use so I thought I could do one in the same style as the Christmas tree I had seen before.  Not knowing where to start I searched for the code of the Christmas Tree (can be found here: http://dnn.itprotoronto.ca/Blogs/tabid/62/EntryId/80/Powershell-Christmas-Tree-ndash-Again.aspx ) and I got to editing.  What I ended up with was great in a massively geeky way to the point I had to show it off.  having shown it to my wife and in-laws where better to next show it off than here.  I will attach the script in a quote below this paragraph and also show off the screen shot.

clear-host
write-host

$Rows = 15
$Slash = 1
    $oldpos = $host.ui.RawUI.CursorPosition

# > sign

    Foreach ($r in ($Slash ..2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14)){
        write-host $("   " * $r) -NoNewline
        1..((($rows +$r) * 0)+1) | %{
                write-Host " ***" -ForegroundColor White  -nonewline
       }
        write-host ""
    }        
    Foreach ($r in ($rows..2)){
        write-host $("   " * $r) -NoNewline
        1..((($rows -$r) * 0)+3) | %{ 
                write-Host "*" -ForegroundColor White  -nonewline
       }
        write-host ""
    }          

    # Underscore

    write-host $("{0}*************************" -f (' ' * ($Rows +10) ))  -ForegroundColor White
    write-host $("{0}*************************" -f (' ' * ($Rows +10) ))  -ForegroundColor White
    $host.ui.RawUI.CursorPosition = $oldpos
    sleep .05

I have to say it’s not the cleanest of scripts possible but it’s a good start.Powershell Logo This blog post has overtaken my last post for what will be published first as I am still writing my other one which is about the PS1 file that is for Powershell scripts but it will be ready soon.   Now you may wonder if this may ever be of use at all but I have a use for it already (besides my profile picture on twitter).  Something else I will cover in the near future is your profile.  In brief your profile is a script that runs when you open Powershell, it is customisable and so as I could I customised it.  I have my profile set so it changes directory to where my scripts live, runs this script to make the logo, then clears the screen again.  It’s not of much use but it’s fun and make Powershell look like it has a boot screen like that of windows when it boots.

So there you have it.  A very useless script but it has a point – I learned about doing something in Powershell whilst having fun.  I am not alone on making pointless scripts for the sake of it and if it’s something you want to do then check out the Scripting Guys scripting games – an annual event for scripters of all levels to try out making a script to for fill a given requirement.

For now anyway it’s time for bed, so have fun learning Powershell and don’t forget to check back another day for more blogs on learning Powershell.

No comments:

Post a Comment