首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PSSession和Get-Hotfix

PSSession和Get-Hotfix
EN

Stack Overflow用户
提问于 2014-03-06 18:56:56
回答 1查看 1.2K关注 0票数 0

我试图远程获取我们服务器上的所有补丁,这样我们就知道什么是什么了。下面是我为实现这一目标而编写的脚本。但是,当我执行脚本时,我只得到运行脚本的本地机器的补丁。我做错了什么?

代码语言:javascript
复制
$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;
     }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-06 19:25:19

Enter-PSSession只具有交互性。对于脚本编写,您需要使用Invoke-Command

代码语言:javascript
复制
$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"
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22233470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档