Create remote gpupdate

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im almost there i think but can someone help me out with this script to solve the problems.Set wshArguments = WScript.Arguments
Set objComputer = GetObject(wshArguments(0))
strComputer = objComputer.dNSHostname
intAnswer = Msgbox("Do you want to Gpupdate: " & strComputer,vbYesNo, "Gpupdate Computer")
If intAnswer = vbYes Then
Call Gpupdate(strComputer)
Else
wscript.quit
End If
Function Gpupdate(comp)
On Error Resume Next
Err.Clear
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select * from Win32_PingStatus where address = " & comp & "")
For Each objStatus in objPing
If objStatus.StatusCode = 0 Then
Host was reachable
Connect to computer
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & objComputer.get("" & strComputer & "") & "rootcimv2:Win32_Process")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & objComputer.get("name") & "rootcimv2:Win32_Process")
Set objProcess = objWMIService.Create("gpupdate /force /t"& comp &" /wait:100", null, null, intProcessID)
Set objProcess = nothing
If Err <> 0 Then
WScript.Echo " Gpupdate failed." & Err.Number & " " & Err.Description
Else
WScript.Echo " Gpupdate initiated..."
End If
Else
WScript.Echo " Host unreachable. Maybe firewall is enabled"
Host was unreachable
End If
Next
End FunctionI really need this. In the contextmenu of Active Directory i select the computer and then the gpupdate. This script needs to do the remote gpupdate.

View the full article
 
Back
Top