Invoke-Command并添加计算机名称列

时间:2016-10-12 13:29:38

标签: powershell

如何添加PSComputerName之类的计算机名列?

Invoke-Command -ComputerName $cpu {
  Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
    Where-Object {$_.DisplayName -like "app"} |  
    Select-Object PSComputerName, DisplayName, DisplayVersion, Publisher, InstallDate |
    Format-Table PSComputerName, DisplayName, DisplayVersion, Publisher, InstallDate
} -ErrorAction SilentlyContinue | Out-File $logFile

1 个答案:

答案 0 :(得分:1)

您正在阅读的注册表项没有值PSComputerName。您可以使用calculated property添加它:

Select-Object @{n='PSComputerName';e={$env:COMPUTERNAME}}, DisplayName, ...