通常在powershell中会定义脚本块(Scriptblock)用于反复调用的一段代码。
定义程序块
PS >$sb ={4*5}
调用程序块
(1)
PS >.$sb
20
(2)
PS >&$sb
20
(3)
PS >$sb.invoke()
20
通常在powershell中会定义脚本块(Scriptblock)用于反复调用的一段代码。
定义程序块
PS >$sb ={4*5}
调用程序块
(1)
PS >.$sb
20
(2)
PS >&$sb
20
(3)
PS >$sb.invoke()
20
2、Professional Windows powershell Programming
http://www.bonashen.com/wp-content/uploads/2010/09/ProfessionalWindowsPowerShellProgramming.pdf
3、Windows powershell Cookbook,2nd
http://www.bonashen.com/wp-content/uploads/2010/09/Windows_PowerShell_Cookbook,2nd.pdf
4、Effective Windows powershell
http://www.bonashen.com/wp-content/uploads/2010/09/EffectiveWindowsPowerShell.pdf
powershell刚开始学,先前网购了一本电子工业出版社出版的《Windows powershell 2.0 应用编程最佳实践》。
后来在网上找到两本powershell的电子书。
1.Windows PowerShell Cookbook™
http://www.bonashen.com/wp-content/uploads/2010/09/OReilly.Windows.PowerShell.Cookbook.Oct.2007.pdf
2.Windows PowerShell in Action
http://www.bonashen.com/wp-content/uploads/2010/09/Manning.Windows.PowerShell.in.Action.Feb.2007.pdf
摘自《Windows PowerShell 2.0应用编程最佳实践》
#pseventing 1.1
#filesystemwatcher
Add-PSSnapin pseventing
$fsw = New-Object system.IO.FileSystemWatcher
$fsw.Path = [IO.Path]::GetTempPath()
$fsw.EnableRaisingEvents = $true
Start-KeyHandler -CaptureCtrlC
Connect-Event fsw changed,deleted -Verbose
"watching $($fsw.path)"
"entering loop ... ctrl+C to exit"
$done = $false
while($events = @(Read-Event -Wait)){
#read-event alays returns a cllection
foreach($event in $events){
switch($event.name){
"ctrlc"{
"cancelling..."
$done = $true
}
"changed"{
$event
#$done = $true
}
"deleted"{
$event
}
}
}
if($done -eq $true){
break
}
}
调试结果如下图: