Is there away to specify which server you want?

63 views Asked by At

The following code or query in powershell allows me to find the number of updates that is needed for a local computer. Is there another way for me to specify which server I want to look at for the number of windows updates. Using -Computername in combination with these script does nothing but gives me error.

$Criteria = "IsInstalled=0 and Type='Software'"
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$SearchResults = $Searcher.Search($Criteria).Updates
$SearchResults.Count
1

There are 1 answers

1
Ansgar Wiechers On BEST ANSWER

You can run the code on a remote host via Invoke-Command:

Invoke-Command -Computer 'someserver' -ScriptBlock {
  $Criteria = "IsInstalled=0 and Type='Software'"
  $Searcher = New-Object -ComObject Microsoft.Update.Searcher
  $SearchResults = $Searcher.Search($Criteria).Updates
  $SearchResults.Count
}

Change the last line to

$env:COMPUTERNAME, $SearchResults.Count

if you want hostname and number of updates returned instead of just the number of updates.