0
votes

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?

1
Hi, you dont have to invoke the command. Get-WmiObject has its own -ComputerName Parameter. Also, what you need to do is expand the property. Just gonna be a little trickier to outputAbraham Zinala
@Abraham could you please re-write the script line for medivya m

1 Answers

1
votes
  • 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:

  • Use Get-CimInstance because Get-wmiobject is deprecated.
  • Do not use win32_product because it can potentially lead to msi corruption. Use the registry instead.

https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/find-installed-software