Reputation: 3
I was executing below script to obtain the server patch version of Skype for business servers.
I need the output as server patch name, version and computername.
$x = Get-Content "E:\temp\servers.txt"
foreach ($y in $x)
{
Invoke-Command -ComputerName $y -scriptblock {Get-WmiObject -query ‘select name, version from win32_product’ | where {$_.name -like “*Skype for Business server 2015, core*”}} | Select-object name, Version, @{Name='ComputerName';Expression={$y}} | ft -AutoSize
}
But I am receiving output as below
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxxx
Name Version ComputerName
---- ------- ------------
Skype for Business Server 2015, Core Components 6.0.9319.598 D221412xxxxxx
I don't need my header tiles in every line of output. Any suggestions?
Upvotes: 0
Views: 440
Reputation: 2904
You are getting headers for each computer because the select statement is inside the foreach loop.
Invoke-command accepts multiple computers so you dont need a foreach loop.
use server-side filtering where possible.
$x = Get-Content "E:\temp\servers.txt"
Invoke-Command -ComputerName $x -scriptblock {Get-WmiObject -query "select name, version from win32_product where name like 'Skype for Business server 2015, Core%'"} |
Select-object PSComputerName,name, Version
For future:
https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/find-installed-software
Upvotes: 1