Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

0

I have a script where part of it looks for pending updates on workstations in the domain. It iterates the following code over all computer members.

$Command = (((New-Object -ComObject Microsoft.Update.Session).CreateupdateSearcher()).Search("IsInstalled=0")).updates  
$Updates = Invoke-Command -ComputerName $Com -Credential $Cred -ScriptBlock {$Command}

But when I run the code (on the DC server locally by just running $Command or remotely by running $Updates), I get the following error:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    + CategoryInfo          : OperationStopped: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException
    + PSComputerName        : SERVER_NAME

I have also tried to run the code locally but gets the same error.

P.S.

I knwo that there is a problem with permissions but I do not know where should I fix it. By the way, I prefer fixing the issue in Powershell not by changing GPO or other settings. I want to make my script unattended.

windows
powershell
windows-server-2016
asked on Server Fault Sep 24, 2019 by ANB • edited Oct 4, 2019 by ANB

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0