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.
5,462 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,328 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Limitless Technology 44,121 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--

    0 comments No comments

  2. Paul Arquette 0 Reputation points
    2023-06-02T19:27:25.0233333+00:00

    Did you ever get an answer to this? I'm running into the same issue.

    0 comments No comments

  3. Jesper Arnecke 0 Reputation points
    2024-07-16T13:44:16.7066667+00:00

    Graveyarding this one.

    Its a security blocker on the file, because cab files are potentially dangerous. You can right click it and even before you get Properties, it will ask to continue because "Internet security settings blocked this file"

    User's image

    You need to either disable this (Not recommended) or make sure you run your Powershell as Administrator, which should bypass this block also.

    0 comments No comments