what causes these download and install powershell errors??

I am using a PowerShell WSUS update script from this site:

I am running it against an Windows Server 2012 R2 server, which so far as I know has Windows remote management already configured on it, any way I can double-check this??

It does not have any ability to inquire directly on the site.

I get these errors thrown back to me:

Exception calling “Download” with “0” argument(s): “Exception from HRESULT: 0x80240024”
At C:\scripts\wsus_update.ps1:58 char:1

  • $Downloader.Download()
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : ComMethodTargetInvocation

Exception calling “Install” with “0” argument(s): “Exception from HRESULT: 0x80240024”
At C:\scripts\wsus_update.ps1:67 char:1

  • $Result = $Installer.Install()
  •   + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : ComMethodTargetInvocation

I’m not an expert PowerShell programmer…

full script code:

# Define server array
$servers = @["sep1"]
# Begin foreach loop
foreach [$server in $servers] {
# Define update criteria
$Criteria = "IsInstalled=0 and Type='Software'"
# Search for relevant updates
$Searcher = New-Object -ComObject Microsoft.Update.Searcher
$SearchResult = $Searcher.Search[$Criteria].Updates
# Download updates
$Session = New-Object -ComObject Microsoft.Update.Session
$Downloader = $Session.CreateUpdateDownloader[]
$Downloader.Updates = $SearchResult
# Install updates
$Installer = New-Object -ComObject Microsoft.Update.Installer
$Installer.Updates = $SearchResult
$Result = $Installer.Install()
# Reboot if required by updates
If [$Result.rebootRequired] { shutdown.exe /t 0 /r }
# Wait 5 minutes before continuing to next server
start-sleep 300
echo 'end of program'
# End foreach loop

Thank you, Tom

You’d probably be best off contacting the original author of the script.

But, are you running this locally, or remotely? I ask because you mentioned remote management; if you’re triggering this remotely, you’re very probably running into the delegated credential problem that trips everyone up. The script probably can’t run against entirely local resources, and so it fails when triggered remotely. It’d work if run locally, if that was the problem.

I can’t contact the original author…the author says windows remote management makes the script possible…

The blog post is kind of old, and has no responses to ANY of the comments, and it was the simplest thing I could find.

How can I address the delegated credential issue?? I am running the script as an administrator account…

My goal is to not have to touch every single server over and over again to run wsus updates hence the script :slight_smile: :slight_smile:

I’ll look for something else if there’s no way to fix the deletaged credential issue…

Thank you, Tom

WinRM has nothing to do with it ;). It’s an old COM object.

Are you running the script locally, or via something like Invoke-Command? Can you run the script locally, as a test, to see if it works that way?

Well, for first try, as you can see, I’m running it against $server = ‘sep1’
I started the script from inside the wsus server.
And I at least remember and know that invoke-command is for running stuff remotely against other servers…though I am not an expert on using it…
And I can see that there’s no invoke-command in the script…

I briefly read up on invoke-command and found this snippet:

# PowerShell Invoke-Expression example from .ps1 file
$Path = "C:\PingWeb.ps1"
Invoke-Expression "$Path" 

Would this have the effect of running my script remotely if I put a parameter to ask me which server??
Or would invoke-expression run the script against all the servers in the array??

I did not immediately find anything wrt invoke-command that would enable the foreach part to work against different servers…

I’ll also continue researching now that I understand I need some sort of invoke call within a ps1 script to run this script against all the servers…

Thank you, Tom


OK, so here’s the thing. You’re not using Windows Remote Management. Period. You’re using the Microsoft.Update COM object, which only reluctantly works from within PowerShell. Now, I’ll tell you what that author probably meant: There’s a Windows Firewall exception for “Remote Management,” which is probably enabling ports that this COM object needs to talk to on whatever server you target. But that’s got nothing to do with (I know it’s confusing) the Windows Remote Management protocol, and nothing to do with PowerShell Remoting, and nothing to do with Invoke-Anything.

This isn’t really “PowerShell,” you’re connecting to external technologies and they’re doing their thing. Unfortunately, I don’t have enough information to tell you what it failing. The only thing I noticed:

$Downloader = $Session.CreateUpdateDownloader[]

Is that should probably be () not []. But I don’t know if that’ll fix what you’re having a problem with at all.

It is () in the script.
The forum pre code thing changed all the parentheses to [], I don’t know why…some of them I found and fixed…
I’ll re-edit the script to make sure they are really parentheses then try again one more time then look for another script…
Thank you, Tom

Hello Tom,

Did you figure out the code to download and install? I am need of a similar code, can you please share.

Bindushree L

the only way to remotely invoke WSUS related COM methods for .Downloader and .Installer - is to use scheduled task manager. btw, Searcher methods work remotely

Try to remotely add new task to your server that run your script “locally” in context of a server.