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 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

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

#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

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

Workflow LongWorkflow
Write-Output -InputObject “Loading some information…”
Start-Sleep -Seconds 10
Write-Output -InputObject “Performing some action…”
Start-Sleep -Seconds 10
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

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

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: