Windows update agent api - Access denied on AddScanPackageService

Zeljko Zaric 1 Reputation point
2023-03-14T12:14:37.4066667+00:00

Hi Together

Could someone help me in this matter...

I am trying to run following script block on remote system to get updates needed and getting access denied on following line:

"

$UpdateServiceManager.AddScanPackageService("Offline Sync Service", "C:\temp\wsusscn2.cab", 1)

"

This is my script.If i start it localy it is working fine.

The user which make remote session is administrator on remote system.



This is error message

$UpdateService = $UpdateServiceManager.AddScanPackageService("Offline Sync Service", "C:\temp\wsusscn2.cab", 1)
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:1
+ $UpdateService = $UpdateServiceManager.AddScanPackageService("Offline ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException

Thanks in advance for your help.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
4,736 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
371 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 15,936 Reputation points
    2023-03-16T15:30:12.6066667+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having query\issues related to Powershell.

    1. Please verify that "Enable Distributed COM on this computer" is Enabled.
    2. Please try to use Invoke-Command to run command from Remote server.

    Invoke-Command -ComputerName Server01 -Credential Domain01\User01 -ScriptBlock

    {

    your command

    }

    1. Disable any Antivirus program or Windows firewall you may have for temporary purpose.

    Reference :

    https://learn.microsoft.com/en-us/powershell/scripting/learn/remoting/running-remote-commands?view=powershell-7.3 https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.3

    --If the reply is helpful, please Upvote and Accept as answer--