functionCopy-Log { "Doing prerequisites" "Testing whether target path exists" "If target path does not exist, bail out" throw"Target path does not exist" "Copy log files to target path" "Delete log files in original location" }
PS> Copy-Log Doing prerequisites Testing whether target path exists If target path does not exist, bail out Target path does not exist In Zeile:8 Zeichen:3 + throw"Target path does not exist" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (Target path does not exist:String) [], RuntimeExceptio n + FullyQualifiedErrorId : Target path does not exist
PS> Copy-Log Doing prerequisites Testing whether target path exists If target path does not exist, bail out Copy log files to target path Delete log files in original location
# URL to RSS Feed $url = 'http://www.spiegel.de/schlagzeilen/index.rss'
$xml = New-Object-TypeName XML $xml.Load($url)
# the subproperties (rss.channel.item) depend on the RSS feed you use # and may be named differently $xml.rss.channel.item | Select-Object-Property title, link | Out-GridView-Title'What would you like to read today?'-OutputMode Multiple | ForEach-Object { Start-Process$_.link }
基本的设计过程是一致的:要将代码改为另一个 RSS 订阅,只需要导航到相应的属性(背后的 XML 的嵌套结构)。
# set the font and size (also applies to Notepad) $path = "HKCU:\Software\Microsoft\Notepad" Set-ItemProperty-Path$path-Name lfFaceName -Value$Font Set-ItemProperty-Path$path-Name iPointSize -Value$FontSize
# enable the preview of PowerShell files $path = 'HKCU:\Software\Classes\.ps1' $exists = Test-Path-Path$path if (!$exists){ $null = New-Item-Path$Path } $path = 'HKCU:\Software\Classes\.psd1' $exists = Test-Path-Path$path if (!$exists){ $null = New-Item-Path$Path }