Re: Script: Remote shutdown of all domain computers in spec. OU

Tech-Archive recommends: Speed Up your PC by fixing your registry



here's a quick script that will ask for the name of the OU in question
like "HOSTS"

then send if the resulting PC's are XP pro SP2 will send the command to
shutdown and reboot in 30 seconds

Const ADS_SCOPE_SUBTREE = 2
on error resume next
dim getOUname: getOUname = inputbox(" Enter name of OU, example HOSTS")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
Set objShell = CreateObject("WScript.Shell")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objRootDSE = GetObject("LDAP://RootDSE";)
strRootDomain = objRootDSE.Get("rootDomainNamingContext")
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, operatingSystemServicePack, operatingSystem " & _
"FROM 'LDAP://OU="; & getOUname & "," & strRootDomain & "' " & _
"Where objectClass='computer' "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF

if objRecordSet.Fields("operatingSystem").Value = "Windows XP
Professional" then
if objRecordSet.Fields("operatingSystemServicePack").Value = "Service
Pack 2" then
objShell.Run ("C:\WINDOWS\system32\shutdown -r -f -t 30 -m \\" & _
objRecordSet.Fields("Name").Value) ,1,FALSE
end if
end if
objRecordSet.MoveNext
Loop
msgbox "done"

.



Relevant Pages

  • Re: Query AD and for each machine frin out the adobe version
    ... Const ForWriting = 2 ... Set objConnection = CreateObject ... When I run the script it goes to the first machine and echos the version ... almost always is the same as the NetBIOS name, ...
    (microsoft.public.scripting.vbscript)
  • Re: VBS Logon and move computer script
    ... tested the script below, but it uses ADO to retrieve info on all computer ... Set objConnection = CreateObject ... Set objRecordSet = Nothing ... > Wscript.Echo strComputer & "Computer exists in Computers" ...
    (microsoft.public.windows.server.scripting)
  • Re: Get ADsPath W2K user
    ... I run the script in which I have adapted according to your suggestions, ... Set objConnection = CreateObject ... WScript.Echo strField ... I am trying to search a Windows 2000 domain for users, ...
    (microsoft.public.scripting.vbscript)
  • Re: Cross Child-Domain Scripting
    ... OR to be able to span child domain LDAP look ups in the same script. ... Set objConnection = CreateObject ... If Err = "0" Then ...
    (microsoft.public.scripting.vbscript)
  • Re: Script works well, but not as scheduled tasks ?
    ... Set objConnection = Wscript.createObject ... 'It's just for testing the script only on ... administrateur (administrator in french, ... The message is logical because the "SDP-HPS-02" PC is already shutdown. ...
    (microsoft.public.scripting.vbscript)