eek! To my friends at CTDotNet.org thank you for your time yesterday. As promised, here are the resources we talked about.
My slides from the session. They contain other resource pointers (like the free eBook), so check them out. If you are behind a corporate firewall, you may have issues accessing the files as I’m hosting on Skydrive (get yours!) and some corporations forbid file sharing. The slides are in 2007 format, so you’ll need the viewer.
Get PowerShell! I showed Version 2 CTP 3. What’s in V2? I like this list on the PowerShell team’s blog – dig around that blog for more goodies.
During my demo, I reached out and showed some cool tricks that I borrowed from various blogs, so in no particular order, check these out (in addition to the PowerShell Team blog):
For folks who want to jump into Windows PowerShell, I stumbled upon this very cool opportunity to attend a session virtually from a Windows PowerShell MVP. The event is today and is open to all!
I used PowerShell to drive my demo script (see below). You should be able to experiment with these at the console.
# Demo Script Powered by start-demo.ps1 # I got a modified version from # http://blogs.msdn.com/powershell/archive/2007/03/06/improved-start-demo-script.aspx # But you should use http://huddledmasses.org/powershell-start-demo-3/ # Code liberally lifted from... # Lee Holmes's Book @ http://oreilly.com/catalog/9780596528492/index.html (Invoke-SqlCommand.ps1, scat is actuall Show-ColorizedContent.ps1) # PowerShell Community Extensions: http://powershellcx.codeplex.com (out-speech.ps1 and get-screenhtml.ps1 are part of the source code) # e.g. http://powershellcx.codeplex.com/SourceControl/changeset/view/48000#302070 ############################################################# # Starting the demos... # Familiar things work Notepad clear-host cls alias cls alias Findstr /? # Dealing with Processes Get-process clear-host Get-help get-process Get-process *ss* Get-process | where {$_.ProcessName -eq "winlogon"} 1..5 | foreach-object {$_ * 2} 1..5 | foreach {$_ * 2} 1..5 | % {$_ * 2} 1..5 | % {if (($_ % 2) -eq 0) {$_ * 2} else {$_}} explorer "http://devcentral.f5.com/weblogs/Joe/archive/2009/01/05/powershell-abcs---k-is-for-keywords.aspx" explorer http://get-powershell.com/2008/12/30/inline-f-in-powershell/ # WMI, Your IT Pro friends will hug you get-wmiobject -list | where {$_.Name -like "*Comp*"} Get-WmiObject Win32_Bios # ADSI Anyone? [ADSI] "WinNT://./Administrator" | Format-List * # Get-Command to Know what you are working with Get-Command –commandtype cmdlet # Other CmdLets with Confirmation and WhatIf restart-computer -confirm restart-computer -whatif # PSDrive is very cool, more later get-psdrive # No .NET Experience needed but if you know .NET... [System.Environment]::OSVersion [System.Environment]::OSVersion.Version [System.DateTime]::Now [System.DateTime] "12/25/2009" - [System.DateTime]::Now get-date | get-member # More .NET Magic [AppDomain]::CurrentDomain.GetAssemblies() | % { $_.GetTypes() } # System.Net and Xml manipulation, out-gridview is new for V2 $digg = ([xml](new-object System.Net.WebClient).DownloadString("http://feeds.digg.com/digg/news/popular.rss")).rss.channel.item $digg | % {$_.title } | out-gridview clear-host # System.Xml.Linq and Reflection param($uri = "http://feeds2.feedburner.com/allandcp") [Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | out-null $rss = [System.Xml.Linq.XDocument]::Load($uri) $rss.Descendants("item") | foreach {$_.Element("title").Value} # Web Services Testing explorer http://www.leeholmes.com/blog/CallingAWebserviceFromPowerShell.aspx #COM Automation $a = new-object -comobject excel.application; $a.Visible = $True; $b = $a.Workbooks.Add(); $c = $b.Worksheets.Item(1); $c.Cells.Item(1,1) = "Title"; $c.Cells.Item(1,2) = "Link"; $i = 2; $digg | foreach-object{ $c.cells.item($i,1) = $_.title;$c.cells.item($i,2) = $_.link; $i=$i+1} $b.SaveAs("$env:USERPROFILE\Documents\ExcelTest.xls"); $a.Quit(); # Say something wicked you naughty PowerShell . .\out-speech.ps1 "I used to be Snow White, but I drifted" . .\out-speech.ps1 "Between two evils, I always pick the one I never tried before. " . .\out-speech.ps1 "When I'm good, I'm really really good; when I'm bad, I'm better. " scat .\out-speech.ps1 . .\get-screenhtml.ps1 > screenshot.html explorer screenshot.html # SQL Skillz - The SQL PowerShell Provider and Calling SQL &"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLPS.exe" $sql = .\Invoke-SqlCommand.ps1 -sqlcommand "SELECT TOP 10 * FROM HumanResources.EMPLOYEE" $sql | out-gridview $sql | get-member scat .\Invoke-SqlCommand.ps1 # IIS Anyone? Using RC1 of IIS PowerShell Snap-in Get-PSSnapIn -registered Add-PSSnapIn WebAdministration # What would you pay to see running request in IIS? IIS 7 Baby!!!! $ie = (new-object -comobject InternetExplorer.Application) $ie.Visible = 1 $ie.Navigate2("http://localhost/demo/sleep.aspx?SleepTime=240") $ie.Navigate2("http://localhost/demo/sleep.aspx?SleepTime=360") get-psdrive cd IIS: dir get-childitem AppPools Get-Command -PSSnapin WebAdministration | select name $wr = Get-WebRequest $wr $wr | get-member c: # More about our Host $Host.Runspace #Show the type format files dir $pshome\*.ps1xml invoke-item $pshome\types.ps1xml invoke-item $pshome\DotNetTypes.Format.ps1xml # Extensible Type System – Extend System.DateTime with a status property $d = new-object([System.DateTime]) $d | add-member –membertype noteproperty –name “Status” –value “*** COMPLETE” $d | get-member $d.Status $d.Status = "*x*x* FAILED" $d.Status Update-TypeData Birthday.ps1xml scat .\Birthday.ps1xml $d | get-member $d.Birthday explorer http://get-powershell.com/2009/02/17/a-method-to-the-add-member-madness/ # The Future is Cloudy – Mount an Azure Blog Storage PS Drive explorer "http://thepowershellguy.com/blogs/posh/archive/2008/11/17/azure-services-training-kit-and-powershell.aspx" C:\AzureSDKSamples\rundevstore.cmd C:\AzureSDKSamples\CloudDrive\scripts\InstallDrive.ps1 C:\AzureSDKSamples\CloudDrive\src\bin\debug\clouddrive.dll C:\AzureSDKSamples\CloudDrive\scripts\MountDrive.ps1 cd Blob: dir
# Demo Script Powered by start-demo.ps1
# I got a modified version from
# http://blogs.msdn.com/powershell/archive/2007/03/06/improved-start-demo-script.aspx
# But you should use http://huddledmasses.org/powershell-start-demo-3/
# Code liberally lifted from...
# Lee Holmes's Book @ http://oreilly.com/catalog/9780596528492/index.html (Invoke-SqlCommand.ps1, scat is actuall Show-ColorizedContent.ps1)
# PowerShell Community Extensions: http://powershellcx.codeplex.com (out-speech.ps1 and get-screenhtml.ps1 are part of the source code)
# e.g. http://powershellcx.codeplex.com/SourceControl/changeset/view/48000#302070
#############################################################
# Starting the demos... # Familiar things work Notepad clear-host cls alias cls alias Findstr /? # Dealing with Processes Get-process clear-host Get-help get-process Get-process *ss* Get-process | where {$_.ProcessName -eq "winlogon"} 1..5 | foreach-object {$_ * 2} 1..5 | foreach {$_ * 2} 1..5 | % {$_ * 2} 1..5 | % {if (($_ % 2) -eq 0) {$_ * 2} else {$_}} explorer "http://devcentral.f5.com/weblogs/Joe/archive/2009/01/05/powershell-abcs---k-is-for-keywords.aspx" explorer http://get-powershell.com/2008/12/30/inline-f-in-powershell/ # WMI, Your IT Pro friends will hug you get-wmiobject -list | where {$_.Name -like "*Comp*"} Get-WmiObject Win32_Bios # ADSI Anyone? [ADSI] "WinNT://./Administrator" | Format-List * # Get-Command to Know what you are working with Get-Command –commandtype cmdlet # Other CmdLets with Confirmation and WhatIf restart-computer -confirm restart-computer -whatif # PSDrive is very cool, more later get-psdrive # No .NET Experience needed but if you know .NET... [System.Environment]::OSVersion [System.Environment]::OSVersion.Version [System.DateTime]::Now [System.DateTime] "12/25/2009" - [System.DateTime]::Now get-date | get-member # More .NET Magic [AppDomain]::CurrentDomain.GetAssemblies() | % { $_.GetTypes() } # System.Net and Xml manipulation, out-gridview is new for V2 $digg = ([xml](new-object System.Net.WebClient).DownloadString("http://feeds.digg.com/digg/news/popular.rss")).rss.channel.item $digg | % {$_.title } | out-gridview clear-host # System.Xml.Linq and Reflection param($uri = "http://feeds2.feedburner.com/allandcp") [Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") | out-null $rss = [System.Xml.Linq.XDocument]::Load($uri) $rss.Descendants("item") | foreach {$_.Element("title").Value} # Web Services Testing explorer http://www.leeholmes.com/blog/CallingAWebserviceFromPowerShell.aspx #COM Automation $a = new-object -comobject excel.application; $a.Visible = $True; $b = $a.Workbooks.Add(); $c = $b.Worksheets.Item(1); $c.Cells.Item(1,1) = "Title"; $c.Cells.Item(1,2) = "Link"; $i = 2; $digg | foreach-object{ $c.cells.item($i,1) = $_.title;$c.cells.item($i,2) = $_.link; $i=$i+1} $b.SaveAs("$env:USERPROFILE\Documents\ExcelTest.xls"); $a.Quit(); # Say something wicked you naughty PowerShell . .\out-speech.ps1 "I used to be Snow White, but I drifted" . .\out-speech.ps1 "Between two evils, I always pick the one I never tried before. " . .\out-speech.ps1 "When I'm good, I'm really really good; when I'm bad, I'm better. " scat .\out-speech.ps1 . .\get-screenhtml.ps1 > screenshot.html explorer screenshot.html # SQL Skillz - The SQL PowerShell Provider and Calling SQL &"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLPS.exe" $sql = .\Invoke-SqlCommand.ps1 -sqlcommand "SELECT TOP 10 * FROM HumanResources.EMPLOYEE" $sql | out-gridview $sql | get-member scat .\Invoke-SqlCommand.ps1 # IIS Anyone? Using RC1 of IIS PowerShell Snap-in Get-PSSnapIn -registered Add-PSSnapIn WebAdministration # What would you pay to see running request in IIS? IIS 7 Baby!!!! $ie = (new-object -comobject InternetExplorer.Application) $ie.Visible = 1 $ie.Navigate2("http://localhost/demo/sleep.aspx?SleepTime=240") $ie.Navigate2("http://localhost/demo/sleep.aspx?SleepTime=360") get-psdrive cd IIS: dir get-childitem AppPools Get-Command -PSSnapin WebAdministration | select name $wr = Get-WebRequest $wr $wr | get-member c: # More about our Host $Host.Runspace #Show the type format files dir $pshome\*.ps1xml invoke-item $pshome\types.ps1xml invoke-item $pshome\DotNetTypes.Format.ps1xml # Extensible Type System – Extend System.DateTime with a status property $d = new-object([System.DateTime]) $d | add-member –membertype noteproperty –name “Status” –value “*** COMPLETE” $d | get-member $d.Status $d.Status = "*x*x* FAILED" $d.Status Update-TypeData Birthday.ps1xml scat .\Birthday.ps1xml $d | get-member $d.Birthday explorer http://get-powershell.com/2009/02/17/a-method-to-the-add-member-madness/ # The Future is Cloudy – Mount an Azure Blog Storage PS Drive explorer "http://thepowershellguy.com/blogs/posh/archive/2008/11/17/azure-services-training-kit-and-powershell.aspx" C:\AzureSDKSamples\rundevstore.cmd C:\AzureSDKSamples\CloudDrive\scripts\InstallDrive.ps1 C:\AzureSDKSamples\CloudDrive\src\bin\debug\clouddrive.dll C:\AzureSDKSamples\CloudDrive\scripts\MountDrive.ps1 cd Blob: dir
Happy PowerShelling!
eek! UPDATE: March 11, 2009 - Here are the resources from the session . Ever wondered what it would be