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

Posted on 2011-04-19
Last Modified: 2012-05-11
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?

Question by:it-infra
    LVL 33

    Expert Comment

    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
    LVL 17

    Accepted Solution



    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 ("")
    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

    LVL 17

    Expert Comment

    by:Tony Massa
    Do the numbers really have to be that big?  Screen HOG, sorry guys, first time I've tried that

    Author Comment


    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:

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

    LVL 17

    Expert Comment

    by:Tony Massa
    This is a VBScript, so it will work on either

    Author Comment

    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.

    LVL 33

    Assisted Solution

    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:
    3) Use Active Directory to publish your new batch file.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
    A quick step-by-step overview of installing and configuring Carbonite Server Backup.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now