Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remote gpupdate script

Status
Not open for further replies.

elmurado

IS-IT--Management
Jul 15, 2003
673
AU
Hi,
I'm trying to run gpupdate remotely on all machines in a domain:
I thought I could copy a script that calls gpupdate to each machine and then run it remotely-however, I'm not sure whether the script I have is going to remotely execute gpupdate(ie on the target machine) or on the server that I am running it from.
Maybe I need to set up a scheduled task.


Code:
'================================
'Script to copy a gpupdate.vbs to a remote computer
'and then run it
'
'===============================
Option Explicit
Dim objFSO, objWSH, strGPUpdateScript, strFileRemote, oTextStream, strComputer, RemotePC, objShell, objWMIService
set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
strGPUpdateScript = "\\ssaserver\Network Admin\Scripts\ADScripts\GroupPolicy\GPUpdate.vbs"

Set oTextStream = objFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer in RemotePC
strFileRemote = "\\" & strComputer & "\c$\Windows\System32\GPUpdate.vbs"
Set objWMIService =  GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
'check if script exists and run it
set objShell = CreateObject("WScript.Shell")
If objFSO.FileExists(strFileRemote) Then
	'WScript.Echo "File is there"
	objShell.Run ("\\" & strComputer & "\c$\Windows\System32\GPUpdate.vbs")
Else
	objFSO.CopyFile strGPUpdateScript, "\\" & strComputer & "\c$\windows\system32\"
	'WScript.Echo "Now file is there"
	objShell.Run ("\\" & strComputer & "\c$\Windows\System32\GPUpdate.vbs")
End If
Next
 
Forgot to give props to MarkD for the meat and bones of the script!
 
All good. Worked out that I can use psexec. Sweet.

Code:
If objFSO.FileExists(strFileRemote) Then
	'WScript.Echo "File is already there"
	objShell.Run ("psexec   \\" & strComputer & " cscript //b c:\Windows\System32\GPUpdate.vbs")
Else
	objFSO.CopyFile strGPUpdateScript, "\\" & strComputer & "\c$\windows\system32\", OVERWRITE_EXISTING
	'WScript.Echo "Now file is there"
	objShell.Run ("psexec   \\" & strComputer & " cscript //b c:\Windows\System32\GPUpdate.vbs")
End If

 
i was going to say, you first script would have just run it loads of times on your own machine :)
 
Glad you figured it out Elmurado and also happy to see the FAQ being of use.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top