如何在循环中使用PowerShell连接字符串?

def*_*foe 1 string powershell foreach loops concatenation

命令

Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Select Name,VMHost | Where {$_ -match "abc" -or $_ -match "def"} | foreach{$_.Name} | Out-File output.txt
Run Code Online (Sandbox Code Playgroud)

将列表写入output.txt,其中只有列名称将在表单中打印:

a
b
c
...
Run Code Online (Sandbox Code Playgroud)

现在我想要实现的是,xxx在某种循环中附加到每一行,以便我得到以下内容:

a,xxx
b,xxx
c,xxx
...
Run Code Online (Sandbox Code Playgroud)

我试图追加字符串,但这似乎不起作用:

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"
Run Code Online (Sandbox Code Playgroud)

我真的不熟悉PowerShell,但我找不到连接的方法,xxx.

在我的情况下,必须在循环中进行连接,而不是之后的文件操作.

Ada*_*ski 8

而不是foreach { $_.Name }foreach { "$($_.Name),xxx" }