當我看到下面的命令的時候,我有點不解,因爲裏面出現了佔位符
Get-WmiObject Win32_Service |ForEach-Object { "{0} ({1}): Path: {2}" `
-f $_.Name, $_.StartMode, $_.PathName }
那佔位符到底是什麼作用,我們看下這個示例,佔位符從0開始,然後1...10之類
佔位符的作用:幫變量佔位置,這樣我們就可以讓格式化輸出
When I saw the first drafts of the scripts, they had a lot of Write-Verbose calls like this one:
$VerbosePreference = “Continue”
$filepath = “C:ps-testtest.txt”
$owner = “juneb”
$result = $true
Write-Verbose (“Created {0} by {1}. Result is {2}.” –f $filepath, $owner, $result)
Here’s the result:
VERBOSE: Created C:ps-testtest.txt by juneb. Result is True.
參考鏈接:
http://social.technet.microsoft.com/wiki/contents/articles/4250.powershell-string-formatting.aspx