2

I've got a powershell script to remote into other computers to get and install windows updates.

I'm logged into the admin account on my local machine. The script starts a powershell remote session into another computer which works fine.

Then once in the remote session the script should run:

Get-WindowsUpdate -AcceptAll -Install -AutoReboot

but i get this error:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    + CategoryInfo          : NotSpecified: (:) [Get-WindowsUpdate], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,PSWindowsUpdate.GetWindowsUpdate

I tried suggested solutions of changing the WMI permissions and I allowed this in the firewall settings but it still did not work.

polo
  • 155
  • 4
  • 11
  • Did you run the instance as admin? Logging into the account doesn't mean you're session becomes *elevated*. – Abraham Zinala May 10 '22 at 15:18
  • I think you have to schedule the updates because of remote powershell permissions. – js2010 May 10 '22 at 17:48
  • 1
    @AbrahamZinala thanks for responding! yeah i ran as admin i believe. From the admin machine i run the the powershell window as administrator. Then i pass the admin credentials to log into remote computer. From what i read my remote session will automatically run with elevated privileges as the admin account has administrative privileges over the target machine: (https://stackoverflow.com/questions/65022178/run-invoke-command-in-remote-computer-as-administrator) – polo May 10 '22 at 17:50
  • @js2010 thanks for responding! do you mean use task scheduler to run the script instead? – polo May 10 '22 at 17:51
  • Yes I think that command has options for it. – js2010 May 10 '22 at 19:58
  • Similar problem - I am not able to remotely start update with Administrator user: Get-WindowsUpdate : The system cannot find the file specified. (Exception from HRESULT: 0x80070002) It works fine for win2019 but fails on win2022(both remote machines) – TestMechanic Sep 16 '22 at 12:06
  • Invoke-WUJob – remotely call WUJobs task in the Task Scheduler to immediately execute PSWindowsUpdate commands; – js2010 Oct 19 '22 at 19:38

1 Answers1

0

I have successfully scripted it by using:

Get-WindowsUpdate -verbose -computer $RemoteServer -AcceptAll -Install -AutoReboot
  • thanks! but i still get the error: VERBOSE: Accepted [8] Updates ready to Download Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) + CategoryInfo : NotSpecified: (:) [Get-WindowsUpdate], UnauthorizedAccessException + FullyQualifiedErrorId : System.UnauthorizedAccessException,PSWindowsUpdate.GetWindowsUpdate – polo May 11 '22 at 09:33