I have below script for checking if an application with name "security" in it is installed or not in remote servers. For example i am searching for two servers. I want to sort the output based on server name.
PS C:\Users\TEMP.DEBPO\Desktop> Get-WmiObject -computerName USWTODWV01,USWPISMWV01 -Class Win32_Product | sort-object co
mputerName,Name | select SystemName,Name | where { $_.Name -match "security"}
SystemName Name
---------- ----
Trend Micro Deep Security Agent
Trend Micro Deep Security Agent
Under system name i want to see computer name. Help is very much appreciated.
Use a calculated property as an argument to select
:
... | Select @{Name='SystemName';Expression={$_.ComputerName}},Name | ...
But you're probably looking for the __SERVER
property of the WMI instance, rather than ComputerName
:
Get-WmiObject -ComputerName USWTODWV01,USWPISMWV01 -Class Win32_Product | Sort-Object __SERVER,Name | select @{Name='SystemName';Expr={$_.__SERVER}},Name | where { $_.Name -match "security"}