2017-09-25 6 views
0

PowerShell 스크립트를 사용하여 테이블을 만들고 결과 (양수/음수)를 테이블에 추가합니다. 모든 PC가 나열된 텍스트 파일 computers.txt가 있습니다. 내 실제 스크립트 난 단지 긍정적 인 결과를 볼 수 있습니다은이핫픽스 KBxxxxxx (예 : KB4012212)가 PC에 설치되어 있는지 여부를 확인하는 방법은 무엇입니까?

 
CSNAME   Hotfixinfo 
PC1    is installed 
PC2    is not installed 
PC3    is installed 
etc. 

처럼

.

Get-Content .\computers.txt | Where { 
    $_ -and (Test-Connection $_ -Quiet) 
} | foreach { 
    Get-Hotfix -Id KB4012212 -ComputerName $_ | 
     Select CSName,HotFixID | 
     ConvertTo-Csv | 
     Out-File "C:\$_.csv" 
} 
+1

당신은'(테스트-연결 $와 _some_ 나쁜 결과를 필터링하는 _ -Quiet) '로 설정하고 나머지는'Get-Hotfix -id KB4012212 -computername $ _'을 null로 사용하면 pipt에 전달되지 않습니다. 더 많이보고 싶다면 각 컴퓨터에 대해 해당 명령을 실행하고 결과를 저장해야합니다. 결과를 확인하면 빈 오브젝트 나 뭔가를 전달할 수있는 것이 없습니다. [pscustomobject] @ {CSName = $ _; HotFixID = "N/A"} – Matt

+0

'computers.txt'는'TSV' 파일입니다. ? – TheIncorrigible1

답변

0

I 좋겠 (파이프 라인 ForEach-Object보다 더욱 빠른) 긍정적이고 부정적인 결과를 통해 분석 및 취급 제안 :

:parse ForEach ($Computer in (Get-Content C:\Path\computers.txt)) 
{ 
    If (Test-Connection $Computer -Quiet) 
    { 
     $Result = Get-Hotfix -Id KB4012212 -ComputerName $Computer -ErrorAction 'SilentlyContinue' 

     If ($Result) 
     { 
      $Result | 
       Select-Object -Property CSName,HotFixID | 
       ConvertTo-Csv -NoTypeInformation | 
       Out-File "C:\$Computer.csv" 
      Continue :parse 
     } 
     "`"CSName`",`"HotFixID`"`r`n`"$Computer`",`"NUL`"" | 
      Out-File "C:\$Computer.csv" 
    } Else { Write-Host 'Unable to connect to $Computer' } 
}