I am trying to write a script that will use the WUA API to install certain updates. I have written many Powershell scripts, but this is my first time using COM objects, or interacting with the WUA API. I have used the code from this article: http://msdn.microsoft.com/en-us/library/windows/desktop/aa387102(v=vs.85).aspx I added in my own code to filter the available updates to a list of updates that I want to install. Everything is working fine, except the script hangs after the calls to both Download() and Install().
When I call Download(), the updates are successfully downloaded, but the script will not continue on. The cursor just sits there blinking. If I monitor WindowsUpdate.log, waiting until the updates are finished downloading, return to the Powershell window, and press the <Enter> key, the script continues on. The same happens with my call to Install().
Here are the sections of code at issue:
'Downloading updates...'
$downloader = $UpdateSession.CreateUpdateDownloader()
$downloader.Updates = $updatesToDownload
$downloader.Download()
"Done"
----------snip------------
"Installing Updates..."
$Installer = $UpdateSession.CreateUpdateInstaller()
$Installer.Updates = $updatesToInstall
$results = $Installer.Install()
"Done"
In neither case is the word "Done" displayed until after I hit <Enter>. The rest of the code is just as it is on the MSDN page linked above (the Powershell version). Why is this happening?