简体   繁体   English

PSSession和Get-Hotfix

[英]PSSession and Get-Hotfix

I am trying to remotely get all the patches on our servers so we know what has what. 我正在尝试远程获取服务器上的所有补丁,因此我们知道有什么。 Below is the script I wrote to achieve this. 下面是我为实现此目的而编写的脚本。 However, when I execute the script I only get the patches for the local machine that is running the script. 但是,当我执行脚本时,我只会得到正在运行脚本的本地计算机的修补程序。 What am I doing wrong? 我究竟做错了什么?

$computers = Get-ADComputer -Filter * -Properties operatingsystem;
$filter = "Windows Server*"

foreach($computer in $computers)
{
     if($computer.OperatingSystem -like $filter)
     {
         $name = $computer.Name.ToString();
         write-host "Working on computer: "$name
         New-PSSession -ComputerName $name;
         Enter-PSSession -ComputerName $name | Get-HotFix | Export-Csv "c:\new\$name patches.csv";
        Exit-PSSession;
     }
}

Enter-PSSession is only usable interactively. Enter-PSSession仅可交互使用。 For scripting you need to use Invoke-Command : 要编写脚本,您需要使用Invoke-Command

$computers = Get-ADComputer -Filter * -Properties operatingsystem;
$filter = "Windows Server*"

foreach($computer in $computers)
{
  if($computer.OperatingSystem -like $filter)
   {
     $name = $computer.Name.ToString();
     write-host "Working on computer: "$name
     Invoke-Command -ScriptBlock {Get-HotFix} -ComputerName $name | 
       Export-Csv "c:\new\$name patches.csv"
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM