【发布时间】:2013-12-22 18:30:53
【问题描述】:
命令
Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Select Name,VMHost | Where {$_ -match "abc" -or $_ -match "def"} | foreach{$_.Name} | Out-File output.txt
向 output.txt 写入一个列表,其中仅列 Name 将打印在表单中:
a
b
c
...
现在我想要实现的是在某种循环中将,xxx 附加到每一行,以便我得到以下内容:
a,xxx
b,xxx
c,xxx
...
我尝试附加字符串,但这似乎不起作用:
Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Select Name,VMHost | Where {$_ -match "abc" -or $_ -match "def"} | foreach{$_.Name} | Out-File output.txt | Add-Content output.txt ",xxx"
我对PowerShell真的不熟悉,也没有找到连接,xxx的方法。
在我的情况下,必须在循环中进行连接,而不是之后的文件操作。
【问题讨论】:
标签: string loops powershell foreach concatenation