I've come across a problem which I can't seem to figure out. I have this piece of code which does exactly what I want. It searches for Windows Updates which are installed and have an specific UpdateID.
param(
$updateId = $false,
$hostName = $false
)
if(($updateId -eq $false) -or ($hostName -eq $false))
{
Write-Host "checkUpdateInstalled.ps1 -updateId <updateIdValue> -hostName <Remote Host Name>"
exit
}
Invoke-Command -ComputerName $hostName -ScriptBlock {
$searcher = New-Object -ComObject Microsoft.Update.Searcher
$searcher.Search("IsInstalled=1 AND UpdateID='$Using:updateId'")
$tmp.Updates| ForEach-Object {
$i++
Write-Host "UpdateInfo Update No. $i"
Write-Host "Title: `t`t" $_.Title
Write-Host "Description: `t`t " $_.Description
Write-Host "UpdateID: `t`t " $_.Identity.UpdateID
Write-Host "RevisionNumber: `t`t " $_.Identity.RevisionNumber
Write-Host "KBArticleIDs: `t`t " $_.KBArticleIDs
Write-Host "==============================================="
}
}
With this solution I can't use $tmp.Updates
outside of the Invoke-Command
but the information I try to gather with the ForEach-Object
Loop works fine. Printing $tmp.Updates
in this case gives me information about the specific update.
So I tried the following to have access to $tmp
:
## Same top part
$tmp = Invoke-Command -ComputerName $hostName -ScriptBlock {
$searcher = New-Object -ComObject Microsoft.Update.Searcher
$searcher.Search("IsInstalled=1 AND UpdateID='$Using:updateId'")
}
$tmp.Updates| ForEach-Object {
$i++
Write-Host "UpdateInfo Update No. $i"
Write-Host "Title: `t`t" $_.Title
Write-Host "Description: `t`t " $_.Description
Write-Host "UpdateID: `t`t " $_.Identity.UpdateID
Write-Host "RevisionNumber: `t`t " $_.Identity.RevisionNumber
Write-Host "KBArticleIDs: `t`t " $_.KBArticleIDs
Write-Host "==============================================="
}
With this attempt the Loop does not print information. If I try to print $tmp.Updates
I just get System.__ComObject
.
Can anyone relate?