New video on the new features of PowerShell 3.0

Sat down this morning and created a new video on the major new features of PowerShell 3.0. It’s uploaded to YouTube and available at http://youtu.be/aQgptbNOBBo. Plus the main code I use throughout the video so you can try for yourself!

#region CIM
Get-Command -Module CimCmdlets
Get-CimClass -ClassName *disk*
Get-CimClass win32* -MethodName Term*
Get-CimInstance Win32_Process
#endregion

#region Simplification example
Get-Process | where {$_.HandleCount -gt 900}
Get-Process | where {$psitem.HandleCount -gt 900}
Get-Process | where HandleCount -gt 900
#endregion

#region Robust sessions
$RemoteSession = New-PSSession –Name Server1Session –ComputerName savdaldc01
Invoke-Command –Session $RemoteSession –ScriptBlock {$date = Get-Date}
Disconnect-PSSession –session $RemoteSession

#This would then be run on the savdaldc01 machine locally showing state not lost
Get-PSSession –ComputerName localhost
$LocalSession = Connect-PSSession –ComputerName localhost  –Name Server1Session
Invoke-command –Session $LocalSession –Scriptblock { $date }
Get-PSSession –ComputerName localhost | Remove-PSSession
#endregion

#region Workflow
Workflow MyWorkflow {Write-Output -InputObject “Hello from Workflow!”}
Get-Command –Name MyWorkflow –Syntax
MyWorkflow

Workflow LongWorkflow
{
Write-Output -InputObject “Loading some information…”
Start-Sleep -Seconds 10
CheckPoint-Workflow
Write-Output -InputObject “Performing some action…”
Start-Sleep -Seconds 10
CheckPoint-Workflow
Write-Output -InputObject “Cleaning up…”
Start-Sleep -Seconds 10
}

LongWorkflow –AsJob –JobName LongWF
Suspend-Job LongWF
Get-Job LongWF
Receive-Job LongWF –Keep
Resume-Job LongWF
Get-Job LongWF
Receive-Job LongWF –Keep
Remove-Job LongWF
#endregion

#region Background job
$Trigger = New-JobTrigger –Daily –At 2am
Register-ScheduledJob –Name MyScheduledJob –ScriptBlock {Get-Process} –Trigger $Trigger
Get-ScheduledJob
(Get-ScheduledJob –Name MyScheduledJob).JobTriggers
Get-ScheduledJob –Name MyScheduledJob
Unregister-ScheduledJob -Name MyScheduledJob
#endregion

#region Misc commands
Get-Command *disk*
Get-Module Get-Disk
Get-Module Show-Command
Get-Command | sort Module | out-gridview
#endregion

Leave a Reply