当我看到下面的命令的时候,我有点不解,因为里面出现了占位符
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