Home > Mobile >  Display the remote computer name
Display the remote computer name

Time:01-21

This is a script to get the version of an installed software on remote computers.

Is there any way I can show the computer names in the result? Please check the screenshot.

$pcname1 = 'TestServer1','TestServer2','TestServer3'

Get-WmiObject -Class Win32_Product -ComputerName $pcname1 |
  where name -eq 'VMware Tools' |
  select Name,Version

enter image description here

CodePudding user response:

Both the obsolete Get-WmiObject cmdlet and its successor, Get-CimInstance,[1] add a .PSComputerName property to its output objects whenever the -ComputerName parameter is used.

Therefore:

$pcnames = 'TestServer1','TestServer2','TestServer3' 
Get-CimInstance -Class Win32_Product -ComputerName $pcnames |
  Where-Object Name -eq 'VMware Tools' |
  Select-Object Name, Version, PSComputerName

[1] The CIM cmdlets (e.g., Get-CimInstance) superseded the WMI cmdlets (e.g., Get-WmiObject) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell (Core) v6 , where all future effort will go, doesn't even have them anymore. Note that WMI still underlies the CIM cmdlets, however. For more information, see this answer.

  • Related