2014-03-06 2 views
0

무엇이 있는지 알기 위해 서버의 모든 패치를 원격으로 가져 오려고합니다. 아래는이 작업을 위해 작성한 스크립트입니다. 그러나 스크립트를 실행할 때 스크립트를 실행하는 로컬 컴퓨터에 대한 패치 만 얻습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?PSSession 및 Get-Hotfix

$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; 
    } 
} 
+0

이러한 컴퓨터 중 c : \ new를 확인 했습니까? 귀하의 PSSessions에있는 귀하의 CSV가 귀하의 PC가 아닌 원격 기계에 있다고 의심됩니다. –

+0

예, 찾고있는 컴퓨터 중 하나를 게시하지 않고 스크립트를 실행중인 로컬 컴퓨터에 배치합니다. 그러나 모든 사람의 권한으로 UNC 경로를 만들었으므로 다음과 같이 표시됩니다. ' '\\ 서버 이름 \ d $ \ Patches \ sample.csv'경로에 대한 액세스가 거부되었습니다. + CategoryInfo : OpenError : (:) [Export-Csv], UnauthorizedAccessException + FullyQualifiedErrorId : FileOpenFailure, Microsoft.PowerShell.Commands.ExportCsvCommand' – Fidelis

+0

WMI를 사용해 보셨습니까? Get-WMIObject Win32_QuickFixEngineering -ComputerName $ name입니다. – EBGreen

답변

1

Enter-PSSession은 대화식으로 만 사용할 수 있습니다. 스크립팅을 위해서는 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" 
    } 
} 
+0

완벽하게 작동했습니다! 나는 일을하기 위해 집회를 사용할 수 있다고 생각했다. 넌 정말 멍청이야! – Fidelis

+0

또는 Invoke-Command를 건너 뛰면'Get-HotFix'는'ComputerName' 매개 변수를 갖습니다. 'Get-HotFix -ComputerName $ name'은 정상적으로 작동합니다. – Duncan

관련 문제