Remote GPO through BATCH Script exiting

batchgroup-policyscriptingwindows-server-2003windows-server-2008-r2

Right so,

I'm trying to make a remote GPO script that from one of our management machines will push the GPUPDATE command to certain servers. After some googling I found a script that I tried to adapt / make run.

The problem however is that when I run it through the BATCH file it errors out on me when doing line 9 (to be fair it doesn't error it just exits the script)

Link to the Script through pastebin:
http://pastebin.com/ugmC9uEr

script code:

@echo on

XPGPORef1=gpupdate.exe /Target:User /force
XPGPORef2=gpupdate.exe /Target:Computer /force

Win2kGPORef1=secedit.exe /refreshpolicy user_policy
Win2kGPORef2=secedit.exe /refreshpolicy machine_policy

For /f “Tokens=*” %%a in (ComputerList.txt) Do (
SET Comp_name=%%a

Ver.exe \\%comp_name% > Hostver.txt

Find /I “XP” < Hostver.txt > CheckCC.txt

IF %errorlevel% == 0 (
Psexec.exe \\%comp_name% Gpupdate.exe /Target:User /force
Psexec.exe \\%comp_name% Gpupdate.exe /Target:Computer /force
) ELSE (
Psexec.exe \\%comp_name% secedit.exe /refreshpolicy user_policy
Psexec.exe \\%comp_name% secedit.exe /refreshpolicy machine_policy
) 
pause

if I run the line 9 code through a DOS prompt window manually and for instance do the following:

For /f “Tokens=*” %a in (ComputerList.txt) Do ( echo %a) 

it will run just fine and echo all the computersnames in the list.

Anyone mind giving me a hand ? 🙂

Cheers

PS: This script is going to try and GPUPDATE both Win2k8/Win2K3 and Win2K computers.

Best Answer

It may be more beneficial to you to lower the Group Policy Refresh Interval on these servers to 5-10 minutes rather than executing a remote gpupdate on all of your servers.