2017-12-21 12 views
0

아래의 명령을 사용하여 KB 값의 정확한 일치를 확인해야한다는 점에서 업데이트 목록의 KB 값을 가져 왔습니다. 모든 것이 가능하지만 -eq의 모든 가능성을 사용했습니다. 얻으려면 완벽하지만 내 경우에는 잘 작동하지 않는 것이 좋습니다. 이 표시 c를powershell에서 다른 개체를 비교하는 방법

$patchID="KB3039714" 
$Session = New-Object -ComObject "Microsoft.Update.Session" 

$Searcher = $Session.CreateUpdateSearcher() 
$historyCount = $Searcher.GetTotalHistoryCount() 
$a = $Searcher.QueryHistory(0, $historyCount) | Select-Object 
@{Name="KB";Expression={[regex]::match($_.Title,'\ 
(([^\)]+)\)').Groups[1].Value}} 
foreach($c in $a){ 
if($c -eq $patchID){ 
$Status="True" 
write-host "exe File Type" 
}else{ 
write-host "Given patchID is not available" 
}} 
+1

"나는이 명령 아래에서 사용 "- 어떤 명령? 그리고 당신은'Get-Member'를 사용하여 객체가 가지고있는 속성을 확인할 수 있습니다. – Raziel

+0

$ c.gettype() String 객체를 반환하지 않지만 PSCustomObject가 이 상황에서 비교하는 방법을 발견했습니다. – hasini

답변

0

당신이 $을 쓸 때 : 그래서

enter image description here

당신이 문자열 $patchID와 출력을 비교하려는 경우, 당신은 객체의 속성 "KB"를 비교해야 당신의 끈으로. 이 같은 다음 중 하나를

$patchID="KB3039714" 
$Session = New-Object -ComObject "Microsoft.Update.Session" 

$Searcher = $Session.CreateUpdateSearcher() 
$historyCount = $Searcher.GetTotalHistoryCount() 
$a = $Searcher.QueryHistory(0, $historyCount) | Select-Object @{Name="KB";Expression={[regex]::match($_.Title,'\(([^\)]+)\)').Groups[1].Value}} 
foreach($c in $a){ 
if($c.KB -eq $patchID){ 
$Status="True" 
write-host "exe File Type" 
}else{ 
write-host "Given patchID is not available" 
}} 

또는 같은

:

$patchID="KB3039714" 
$Session = New-Object -ComObject "Microsoft.Update.Session" 
$Searcher = $Session.CreateUpdateSearcher() 
$historyCount = $Searcher.GetTotalHistoryCount() 
$a = $Searcher.QueryHistory(0, $historyCount) | Select-Object 
@{Name="KB";Expression={[regex]::match($_.Title,'\(([^\)]+)\)').Groups[1].Value}} 
if($a.KB.Contains($patchID)){ 
$Status="True" 
write-host "exe File Type" 
}else{ 
write-host "Given patchID is not available" 
}} 

조금 더 PowerShell을-개체에 어쩌면 당신은 읽어야한다,이 문서는 매우 잘 설명 : https://technet.microsoft.com/en-us/library/ff730946.aspx