Windows Update script using powershell not working
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.
Thanks
Comments
-
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. https://support.atera.com/hc/en-us/articles/218040797-Run-a-script
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.
0 -
That sort of worked. Tested on a computer - it didn't like the
Stop-Service wuauserv
Set-Service wuauserv -StartupType DisabledReplaced it with
net stop wuauserv
Set-Service wuauserv -StartupType Disablednow 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.
0 -
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.
0 -
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!1
Topics
- All Topics
- 41 Getting started
- 25 Read before posting
- 8 Meet and greet
- 237 General
- 64 News and announcements
- 1 Swag
- 1 Roadmap updates
- 79 Resources
- 12 Knowledge Base
- 16 Webinars
- 1 Shared Script Library
- 2 Blog
- 19 Pro Tips
- 27 Got an idea?
- 3 Atera Academy
- 2 ActionAI
- 1 Copilot
- 140 Remote Monitoring and Management
- 84 Remote Monitoring
- 27 Patch Management
- 105 Professional Services Automation
- 64 Helpdesk
- 17 Billing
- 21 Reporting
- 36 Integrations & add-ons
- 20 Integrations
- 10 Add-ons
- 103 Scripting and automations
- 61 Scripts
- 30 Automations