Powershell WUA script hangs on calling Update() and Install()

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?

I think I have found the solution to my problem.
I changed this line:
$downloader.Download()
to this:
$dresult = $downloader.Download()
Now the script runs. Apparently, if I try to ignore the return value of that function it clobbers something. I am used to just ignoring return values when I don't want them. (I know that ignoring return values is not a good practice, but this script is not
intended to be robust. It will only be used occasionally, and only by me.)
Thank you for the link, jrv. It got me going in the right direction.

Similar Messages

  • WSUS Hangs on "Unused updates and update revisions"

    In our environment we have not cleaned up WSUS updates in a while, probably about a year. I have been tasked with cleaning it up and optimizing it. When I attempt to run the WSUS Server Cleanup Wizard, it hangs on "Unused updates and update revisions"
    and doesn't do anything. The wizard then disappears and I am taken back to the WSUS Console where I see the following:
    Error: Database Error
    When I click copy error to clipboard, this is what is copied:
    The WSUS administration console was unable to connect to the WSUS Server Database.
    Verify that SQL server is running on the WSUS Server. If the problem persists, try restarting SQL.
    System.Data.SqlClient.SqlException -- Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
    Source
    .Net SqlClient Data Provider
    Stack Trace:
    at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
    at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
    at Microsoft.UpdateServices.UI.SnapIn.Wizards.ServerCleanup.ServerCleanupWizard.OnCleanupComplete(Object sender, PerformCleanupCompletedEventArgs e)
    In my research, I have found several solutions, and have tried a few of my own. Below I will list the ones I have tried: 
    1. Run each item individually. IE, run superseded updates, then run expired updates after that finishes, then run unneeded update files after that finishes, etc. This did not work
    2. Stop the WSUS IIS service and run "wsusutil.exe removeunneededupdates" this also did not work
    The solutions I have found, but am hesitant to try (due to the fact that we are in a live production environment) are the following:
    1. Re-Index the WSUS Database according to the following link: 
    https://technet.microsoft.com/en-us/library/dd939795(v=ws.10).aspx
    2. Deleting the files in the WSUS folder and running "wsusutil.exe reset" from the following link: 
    http://windowsitpro.com/windows/quick-tip-resetting-wsus-server
    I would like to know what, if any, impact either of these solutions will have on our environment, and which one would be the preferred method. I feel like I should use the first one, and if I still don't have any luck then try the second. My only concern
    with the second method is that it might break something (not sure what, except updates). 
    A little about our environment - 8,000 computers, WSUS and SCCM are on the same Server 2008 R2 server, we only have the one WSUS and SCCM server, so nothing downstream as far as WSUS is concerned. 
    Thanks everyone!

    UPDATE:
    I have started going through and declining updates, and then going through SCCM and removing any expired updates from the SCCM side as well. I am now down to 3822 unapproved updates in WSUS, with a total of 13304 updates.
    At this point I am STILL UNABLE to run the cleanup wizard to clean up any of these. It still hangs when it runs, and only on Unused Updates and update revisions. I have even tried running powershell scripts and command line utilities to clean WSUS up, and
    still just hangs. I am pretty much at a loss, so any other advice would be appreciated.
    One more question, should it resort to this: What impact does resetting WSUS have on a live environment, with 7000 plus computers? Should I have to resort to it, is this something that is going to cause any major issues? 
    We do plan on preventing this in the future by running the database defrag once a month, and running the WSUS Server Cleanup Wizard once per quarter, but getting there sure is proving to be quite the challenge.
    Thanks again!

  • I am trying to use a website that requires that my computer have the lastest version of Java, which I have updated and installed, however Firefox does not recon

    I am trying to use a website that requires that my computer have the latest version of Java, which I have updated and installed Java 7 Update 51 (64-bit), however Firefox does not recognize that I even have Java on my computer. My computer is 64-bit
    When I run "Verify Java Version" it show nothing is installed... but it is, I know that for a fact because it shows in my "Control Panel/Programs/Programs and Features".
    When I go back to the Java Download page, the following message is visible:
    "We have detected you may be viewing this page in a 32-bit browser. If you use 32-bit and 64-bit browsers interchangeably, you will need to install both 32-bit and 64-bit Java in order to have the Java plug-in for both browsers."
    My question is this:
    Is there a way to change my Firefox browser from 32-bit to 64-bit.... because it appears that this is way Java is not functioning properly?

    Firefox needs 32-bit plugins, so you'll need to install 32-bit Java for Firefox.
    No, you can't change Firefox from 32-bt to 64-bit. There is a Nightly 64-bit version (alpha) of Firefox, but it is used only to test for regressions until development is resumed.

  • On my old iTunes sofwear iTune store would not open. I uninstalled iTunes and downloaded the new updates and installed it. Now I get a message that said " The file iTunes Libary.itl" cannot be read becouse it was created by a newer version of iTunes.

    On my old iTunes sofwear iTune store would not open. I uninstalled iTunes and downloaded the new updates and installed it. Now I get a message that said " The file iTunes Libary.itl" cannot be read becouse it was created by a newer version of iTunes.I did everything it said to do inarticle HT1923 Removing and reinstalling iTunes, Quick Time, and other sofware components for Windows Vista or Windows 7. Now what?

    Unless you've recently attempted to downgrade iTunes this is probably a sign of a corrupt library file. See Empty/corrupt library after upgrade/crash.
    tt2

  • I recently did a system update and installed Yosemite on my Mac. Now I am unable to open CS5 at all. The error message I get is this: "To open Adobe Photoshop CS5.1, you need to install legacy Java SE 6 runtime." I have tried downloading this and it still

    I recently did a system update and installed Yosemite on my Mac. Now I am unable to open CS5 at all. The error message I get is this: "To open Adobe Photoshop CS5.1, you need to install legacy Java SE 6 runtime." I have tried downloading this and it still gives me the same mess

    In the details it is mentioned that it is an outdated version of Java.
    Is this a security risk that i need to live with to get CS5 to run with Yosemite?
    Also i need to reject messages from Java in the future about updates, or not?
    thx for any input

  • I have an iMac that I am running OSX 10.8.3 on.  I keep trying to install 10.8.4 but it will not install.  I tried updating and installing several times and it restarts the computer but it will not install the software.  My machine is about 8 months old.

    I have an iMac that I am running OSX 10.8.3 on.  I keep trying to install 10.8.4 but it will not install.  I tried updating and installing several times and it restarts the computer but it will not install the software.  My machine is about 8 months old so, it's in the newish range.  HELP!

    Sometimes the App Store version doesn't work correctly. In this case, install 10.8.4 with the Combo version > http://support.apple.com/kb/DL1659?viewlocale=en_US&locale=en_US
    The Combo installer is the safest way to update OS X, and it allows you to update more than one computer with a single download

  • I'm trying to update my application and it is asking me to change my billing account it is not accepting the security code. I am not trying to buy an application just to update and install free apps

    I'm trying to update my application and it is asking me to change my billing account it is not accepting the security code. I am not trying to buy an application just to update and install free apps

    So why are you posting on this forum?  We're users here, not Apple.  Click the "Contact Us" link in the lower right hand corner of this page.

  • How can I get rid of this number even though all apps are updated and installed?

    Weird problem - How can I get rid of this number on top right even though all apps have been updated and installed?

    stamatgeorge wrote:
    Weird problem - How can I get rid of this number on top right even though all apps have been updated and installed?
    That doesn't mean that you have updates.
    Not sure how that app works, - normally means you have a notification for that app - what happen when you go into the app?
    If you had update it would be a red number for the app store icon

  • Have photoshop cs5 installed on desktop..got new Canon rebel T5i camera...cannot open RAW images...updated and installed plug-in...still now working.  Need help, please.

    I have photoshop cs5 installed on desktop...got new Canon rebel T5i camera...cannot open RAW images...updated and installed plug-in...still not working...help please.

    In any event, that camera was first supported by ACR version 7.4 which needs at least CS6 to run.  Naturally, all later versions support it too.
    Your choice is either to upgrade your Photoshop, or to look for, download, install, launch and run the free, stand-alone Adobe DNG Converter 8.6 on each folder containing your raw Canon files to convert them first to raw DNGs that you can open in CS5.
    In no case does an Adobe application belong "on your desktop".  The default install location should always be respected and left alone.

  • HT201210 what is unknown error(1) !!! it appears every time i tried to update and install iphone soft ware!!! Further, that error appears once the firmware installation is in process !!!

    what is unknown error(1) !!! it appears every time i tried to update and install iphone soft ware!!! Further, that error appears once the firmware installation is in process !!!

    Usually occurs on devices that have either been jailbroken or attempts have been made to downgrade the iOS.  You can try putting it in DFU mode to restore but you may not be able to fix it.  If you phone has been jailbroken we can't support you in these forums as it is against the terms of use.

  • HT2052 how i recover my iphone3GS, because i try to update and install iOS 6.01...then suddenly itunes logo appear...

    how i recover my iphone3GS, because i try to update and install iOS 6.01...then suddenly itunes logo appear...

    Your phone is in recovery mode. Did you plug it to the computer running itunes? What happend?

  • HT5704 Hello I am having problems updating my iPhone to iOS 613  why I'm following instruction  but its not happening. I'm going to settings  ,general  and update and install and nothing happens would u please help

    Hello I'm trying to update my I phone 5 to iOS 6 but is not letting me I'm following the instructions. I
    Go to settings  , update and install but nothing is happening can u please help me what am I doing wrong 
    Thanks evelyn

    Can anyone help

  • HT3702 My apple id unable to update and install the software from my iphone

    My apple id unable to update and install the software from my iphone.I had checked the purchased history and found that my last payment had failed.I went to the bank to check my debit card status.But unable to found any problem from the bank.Had confirmed that my debit card have sufficient money to deduct.Pls help me as soon as possible ...
    Thanks,
    Jay Tan

    When you select update, verify that it is showing your correct Apple ID, perhaps you have an app that was downloaded with a different ID, all apps are always associated with the ID that first downloaded them.

  • When Updating and Installing New System

    When Updating is Good but when installing is failed. i Don't know what happen.. but i will try 2nd update and install again... 
    Xperia Z2
    Solved!
    Go to Solution.

    Could you elaborate? are you using Bridge? PCC? OTA?
    PC Companion (PCC)
    Bridge (for Mac)
    Alternatives on How to backup Xperias
    http://talk.sonymobile.com/thread/36355
    "I'd rather be hated for who I am, than loved for who I am not." Kurt Cobain (1967-1994)

  • Hi guy!...i cannot update and install app from app store after upgred to iOS 6.1...any idea how to fix this..tq!..

    please help me to fix this problem on my iphone 5....cannot update and install app from app store after upgrade to iOS 6.1...

    9w6sun wrote:
    ..cannot update and install app from app store after upgrade to iOS 6.1...
    what happens when you try...?
    Any error messages or Alerts.

Maybe you are looking for

  • Create Attachment through Generic Object Services (BC-SRV-GBT)

    Hello experts, I have one question about a storing of document in this functionality. As you know there are several ways of storing a document to some object. 1. Using the menu: "Create - Create Attachment" 2. Using the menu: "Create - Store  Busines

  • How to access the ejb using WSIF

    I have deployed my Bean Managed Persistance Entity Bean in Weblogic 8.1 App Server. Trying to access the ejb from Synchronous BPEL process using WSIF. I am getting following error - WSIF0011I: Preferred port 'EJBPort' was not available org.apache.wsi

  • PLEASE HELP - MORE & MORE MUSIC SKIPPING!

    I started with a small problem a year ago and now more and more music skips - I update as offered so I have the lastest version all the time. Can you help?

  • Webserviec : XI 3.0 to PI7.1

    Hi, We are in the process of migration from XI 3.0 to PI 7.1. We had a few webservice scanarios in XI 3.0 where the urls for thes interfaces to be used by partner application to call XI were generate using the ID -> Tools -> Define Web Service. We ar

  • How can I translate a document in Adobe fom Spanish to English

    How can I translate a document in Adobe fom Spanish to English