简体   繁体   中英

Invoke-Command and add computer name column

How can I add some computername column like 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

The registry key you're reading doesn't have a value PSComputerName . You can add it with a calculated property , though:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM