Windows Update script using powershell not working

steves3cc Member Posts: 2

In the shared script library, there is a windows update script called Pause 30.

The description is: This will first stop Windows Update service and disable it from running at startup. Then it enters 30 for the number of days to pause windows updates for. Last is it creates a one-time scheduled task that starts the Windows Update service at the new date specified.

Here is the .ps1 script:

#Stops Windows Update and disables it on Startup
Stop-Service wuauserv
Set-Service wuauserv -StartupType Disabled

#Prompt user to select # of days to pause updates for
$newdate = (Get-Date).AddDays(30)

#Create a New Scheduled Task to run at date specified above
New-ScheduledTaskTrigger -At $newdate -Once

#Sets new task action to open powershell and start the update service
$action = New-ScheduledTaskAction -Execute "Powershell.exe" `
-Argument '-NoProfile -WindowStyle Hidden -command {Start-Service wuauserv}'

#Sets trigger action to happen once at the new date specified
$trigger = New-ScheduledTaskTrigger -at $newdate -Once

#Creates the New Scheduled Task
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "PauseWinUpdates" -Description "Powershell script to pause Windows Updates until a certain date that is specified by the user"

This script requires elevated privileges to run. How can we push this script with elevated rights? Any idea how to do this? I ran this manually on a computer without evelated and it failed.



  • dragos.t
    dragos.t Support Moderator Posts: 42 admin

    Hello @steves3cc,

    Hope you are doing well.

    Running the script with elevated privileges means running the script with Admin rights on the device.

    From Atera you might be able to run the script from Atera using Admin rights, as long as there are no limitations when running the script as System.

    Clone the script on your Atera instance, then open the script in Atera click on Edit script, then click on Currnet User, next to Run as.

    Then, on the next windows, click on System and Apply, then save the changes to the Script. You could also test running the script as a Current User, that might also work, but it depends on the privileges of the currently logged-on user.

    This should allow you to run the script using Admin privileges, as long as there are no limitations when it comes to running the script using the built-in System account in Atera.

    If you wish to run the script locally on your devices, I suggest using something like Powershell ISE. Search for Powershell ISE on your Windows device, right-click on it, and select Open as Administrator. In PS ISE, you have the option to paste the script inside the window and click on Run.

  • steves3cc
    steves3cc Member Posts: 2

    That sort of worked. Tested on a computer - it didn't like the

    Stop-Service wuauserv
    Set-Service wuauserv -StartupType Disabled

    Replaced it with

    net stop wuauserv
    Set-Service wuauserv -StartupType Disabled

    now that works, but creating the task fails. When I run the ps1 file locally on the computer. Everything works. When I push the script through Atera - only 1/2 works (the service stops and disables, the Get-Date output works. But the scheduled task failes.

  • dragos.t
    dragos.t Support Moderator Posts: 42 admin

    That could be due to a limitation of how the System account works or it might be the script. Please keep in mind that we don't troubleshoot scripts from the Shared script library, but you could do something with ChatGPT.

    If you receive an output from Atera, you can copy the output the go to ChatGPT.

    You can first use a prompt like "Act as a professional PowerShell developer and fix the following script", then you add the script and the output you receive in Atera. ChatGPT will then attempt to fix the script.

  • gilgi
    gilgi Administrator, Moderator Posts: 101 admin

    Using AI is certainly beneficial.
    I'd like to chiming in the Copilot can also do that without the need of the prompt and deliver refined results within the IT space.
    And also that if you have a fix you are most welcome to upload your version for others to use in the future, it's a library for all.

    thanks @dragos.t for the great tips!