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

x
  • 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?


Thanks
0
it-infra
Asked:
it-infra
  • 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
0
 
Tony MassaCommented:

1

Create a new GPO for the script.

2

Configure the GPO:

3

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

4

Under STARTUP, click "ADD"

5

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

6

Click on "SHOW FILES"

7

Create a new TEXT file in this folder

8

Rename it to "Clear-Updates.vbs"

9

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

10

Close the "STARTUP" folder

11

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

0
 
Tony MassaCommented:
EE:
Do the numbers really have to be that big?  Screen HOG, sorry guys, first time I've tried that
0
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:
@tmassa99

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?

Thanks
0
 
Tony MassaCommented:
This is a VBScript, so it will work on either
0
 
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.

Thanks
0
 
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.
0

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