Powershelling again - day 1
I haven't seen PowerShell for last 2 years, so I was pretty curious what will be my learning curve now - if it will be like riding bicycle (once you know it, you will never forget it) or if I will spend countless number of sleepless hours trying to copy one file.
Well, I was surprised how easy it was to start using PS... I decided that I will try to do everything from PowerShell today - not only some manipulation with files, but also reading emails, replying to messages or listening to music... When I say everything, I really mean it :D And it was not always easy ;)
At first I checked few sources I remembered - first Mow's excellent blog, but also PowerShell Analyzer and tons of other great resources (of course all blogs from MS PS team)... BTW I can highly recommend Top 10 tips for using Windows PowerShell at WindowsDevCenter, basic stuff there, but you can refresh your memory really quickly.
Getting help
I was able to remember how to use PS almost immediately (Jeffrey, if you are reading this, you have done GREAT job on PowerShell, it is very easy to use once you remember few rules). Of course I forgot some bits, but after implementing MSDN (and Google ;)) function on System.Object (as described by Jeffrey 2 years ago) and installing PowerTab from Mow, I had all I needed. Function Get-Member (my favorite cmdlet in PowerShell) was my best friend again ;)
BTW if you want to have also Google option, use following snippet in type definition:
<ScriptMethod>
<Name>Google</Name>
<Script>
if (($global:IE -eq $null) -or ($global:IE.HWND -eq $null))
{ $global:IE = new-object -ComObject InternetExplorer.Application
}
$global:IE.Navigate2("http://www.google.com/search?hl=en" + [Char]38 + "q=" + $this.GetType().FullName)
$global:IE.Visible = $TRUE
</Script>
</ScriptMethod>
First command
But of course I started with Hello World - and because Hello World is too easy in PS, I tried something more complex:
BTW I did the code right on first try - but because (due to small experiment I tried before) .NET itself for corrupted, form only blinked and disappeared, so I spend lot of time trying to figure out why it doesn't work (BTW Mow, if you read it, it would be nice if PowerTab could support Enums, I remembered that 5 = Fill only by accident ;))
Oops, mail arrived
While playing with Hello World new email arrived - so I tried to read it - and it was not that easy ;)
After few trial\error tests I came up will really dirty one-liner (of course it will be slow, but I just wanted to see that email without opening Outlook and then just kill Outlook.exe):
$(New-Object -ComObject Outlook.Application).GetNamespace("MAPI").GetDefaultFolder("olFolderInbox").Items | Where {$_.Unread -eq $True} | Select Body | Format-List
As I said, this is definitely not something I should be proud of, but it was working ;)
Messenger message
Later on I received message (Live Messenger) from my girlfriend... I spend some time trying to somehow manage messenger from PS, but no luck :( When I saw that window is really blinking and it is obvious that I am behind computer not replying to her messenger, I left PS and replied - I gave up the fight with COM interface of Messenger ;)
PowerShell Community Extensions
Before running powershell I installed PSCX from CodePlex (http://www.codeplex.com/PowerShellCX) - they are different extensions for PowerShell, some of them are very nice, some of them are not and I already found few problems (especially in CD function, but I didn't really have time to debug and fix it yet). What is really nice that (as far as I see) 2 providers are added - AD and Feeds.
I am thinking about writing some providers for myself, just to test that functionality.
PSCX is nice project, however I think I will really need to have a look and remove stuff I don't want (it slows down PS quite a lot and I already encountered few problems).
SysInternals
Later that day I run into problem when one of my files was locked by something - I wanted to use Handle from SysInternals, but then I figured out that I don't have it locally yet. At first I thought I will try to download that file using PS, but then I realized that SysInternals recently went Live (most sites reported that http://live.sysinternals.com/ is live - it is just web page. More interesting is file://\\live.sysinternals.com ;)).
So I tried to access it directly (cd \\live.sysinternals.com\Tools), however without luck - there is problem in CD.ps1 from PSCX. I wanted to remove CD.ps1, but then I realized I can map it as PSDrive...
I tried New-PSDrive -Name SysInternals -PSProvider FileSystem -Root \\live.sysinternals.com\Tools - and it worked like a charm :) So now I can simply use cd SysInternals:
PowerShellPlus
I think PowerShell is extremely cool - and I think biggest drawback is still cmd host... I spent some time (few months ago) searching for some replacements, however there are none (tools like Console etc are not really what I am looking for). For powershell I remembered I was using PowerShell Analyzer as beta tester, so I downloaded PowerShellPlus (currently in beta) from same author and I am veeeeery very happy :)
Only thing I am missing is global shortcut for Mini-Mode, otherwise it is perfect (and free for non-commercial use).
You will also get nice Code Editor with it:
Well, that was my first day with PowerShell after 2 years :) From now on I can start using it on daily basis and I am really glad I can finally forget about all batch scripts - it was fun sometimes, but I can finally leave DOS past behind and focus on .NET future :)