[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 580
  • Last Modified:

How to write a script and run it on Group Policy?

Hello All,

I'm running WSUS and for some reasons I wanna run the following:

1- Net Stop WUAUServ
2- Delete C:\Windows\SoftwareDistribution
3- Net Start WUAUServ

These 3 commands will stop updating service, delete updates that might be corrupted then restart the service, how to write such a script and how to implement it on Group Policy?

  • 3
  • 2
  • 2
2 Solutions
Paul MacDonaldDirector, Information SystemsCommented:
1. Write your script and save it in your domain's SYSVOL\<domainname>\Scripts folder.
In ADUC create or edit a GPO.
2. Go to the Computer or User Configuration, depending on how you want your script to run.
3. Under Window Settings > Scripts you'll see StartUp and Shutdown (or Logon and Logoff).  Double-click the event you want and "Add..." the script
Tony MassaCommented:


Create a new GPO for the script.


Configure the GPO:


Computer Configuration\Windows Settings\Scripts (Startup/Shutdown)


Under STARTUP, click "ADD"


Under ScriptName, enter "Clear-Updates.vbs" (nothing else but the name)


Click on "SHOW FILES"


Create a new TEXT file in this folder


Rename it to "Clear-Updates.vbs"


Edit, and paste the contents of the attached script and SAVE IT!


Close the "STARTUP" folder


Hit OK to save the setting and OK to SAVE the policy
'Call this script 'Clear-Updates.vbs'
On Error Resume Next

Set objShell = WScript.CreateObject ("WSCript.shell")

objShell.Run ("net stop wuauserv"),1,True
objShell.Run ("del %windir%\SoftwareDistribution"),1,True
objShell.Run ("net start wuauserv"),1,True

Open in new window

Tony MassaCommented:
Do the numbers really have to be that big?  Screen HOG, sorry guys, first time I've tried that
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

it-infraAuthor Commented:

Will that work with earlier OS like XP? cuz I got this note:

"PowerShell scripts requires at least Windows 7 or Windows Server 2008."

However I found this article: http://social.technet.microsoft.com/Forums/en/winserverGP/thread/a8921d68-5115-448a-b489-16b941a971f6

So is the above script written to work on legacy OS too?

Tony MassaCommented:
This is a VBScript, so it will work on either
it-infraAuthor Commented:
I modified the code to be a batch as follow:

net stop wuauserv
rd /s /q %windir%\SoftwareDistribution
net start wuauserv
%windir%\system32\wuauclt.exe /detectnow

Open in new window

I configured it to be on startup however I wanna do it only once on a specific time, is there a way to do it? Like I wanna run the script on 6 PM everyday.

Paul MacDonaldDirector, Information SystemsCommented:
Hmm.  Then you'll need a script to do that.  

1) Take your batch file (net stop wuauserv...) and put it somewhere all your machines can get to it.
2) Create another batch file with something like
     AT 18:00 /every:M,T,W,Th,F,S,Su cmd /c "\\path to your batch file\FixWindowsUpdate.bat"
     (for more info: http://support.microsoft.com/kb/313565)
3) Use Active Directory to publish your new batch file.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now