Powershell 对象属性未显示

Powershell object attribute not showing

知道为什么 $result.PathName 不起作用吗?

$results = Get-WMIObject -query "select * from Win32_Service where Name LIKE '%sql%'" | Select Name, PathName | Format-List
ForEach ($result in $results) {
    Write-Output "Test = " + $result.PathName
}        
Write-Output "done"

预期输出:

Test = C:\blah\blah.sqlserver.exe
Test = C:\blah\blah.sqlserver.exe

实际产量

Test =
+
Test = 
+

Format-* cmdlet 生成格式化指令作为输出。除了向用户显示结果或用于 Out-* cmdlet 之外,此说明对任何事情都没有用。从代码中删除 Format-List。并将表达式放在 Write-Output 之后的括号中:Write-Output ("Test = " + $result.PathName),将其解释为单个表达式而不是 Write-Output 的三个不同参数。或者您可以完全删除默认情况下暗示的 Write-Output