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