找到你要的答案

Q:Is there away to specify which server you want?

Q:是否有指定您想要的服务器?

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

下面的代码或查询在PowerShell中让我找到更新,是本地计算机所需要的数。是否有另一种方式,我指定哪些服务器,我想看看的数量的Windows更新。使用与这些脚本组合计算机只会让我错误。

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

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.

可以通过调用命令在远程主机上运行代码:

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
}

改变最后一行

$env:COMPUTERNAME, $SearchResults.Count

如果你想返回主机名和更新的数量而不是更新的数量。

scripting  server  powershell-v2.0  updates