madmardegon
MIS
Hi everyone, I am pretty new to scripting and I am trying to practice as much as possible I have a script that is functioning almost correctly there is just one part that I cannot get to work right. Any ideas would be much appreciated. First here is what the script does:
1. Enumerate an active directory group
2. Ping all the members of the group
3. If the member is turned on restart the machine
4. If it is not on write the word DOWN
5. And if it pings, remove the member from the group
So, here is my code.....
On Error Resume Next
Set objGroup = GetObject _
("LDAP://cn=group,ou=domain, dc=OU, dc=net")
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
For Each strMember in arrMemberOf
xcomputer = split(strmember,",")
xname = mid(xcomputer(0),4,len(xcomputer(0))-1)
if Ping( xname ) = True then
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & xname).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
If Ping( xname ) = True then
for each xname in arrMemberOf
objGroup.Remove("LDAP://" & xname)
objGroup.SetInfo
next
end if
next
else
strStatus = "DOWN"
end if
wscript.echo strStatus
Next
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
Ok, everything works the way I want it to except one part. When the computer reboots and is supposed to be removed from the group, the script instead removes every member of the group at one time instead of stepping through each one. Again any advice for the rookie would be greatly appreciated.
Thanks,
Brandon
1. Enumerate an active directory group
2. Ping all the members of the group
3. If the member is turned on restart the machine
4. If it is not on write the word DOWN
5. And if it pings, remove the member from the group
So, here is my code.....
On Error Resume Next
Set objGroup = GetObject _
("LDAP://cn=group,ou=domain, dc=OU, dc=net")
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
For Each strMember in arrMemberOf
xcomputer = split(strmember,",")
xname = mid(xcomputer(0),4,len(xcomputer(0))-1)
if Ping( xname ) = True then
Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & xname).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
for each OpSys in OpSysSet
OpSys.Reboot()
If Ping( xname ) = True then
for each xname in arrMemberOf
objGroup.Remove("LDAP://" & xname)
objGroup.SetInfo
next
end if
next
else
strStatus = "DOWN"
end if
wscript.echo strStatus
Next
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
Ok, everything works the way I want it to except one part. When the computer reboots and is supposed to be removed from the group, the script instead removes every member of the group at one time instead of stepping through each one. Again any advice for the rookie would be greatly appreciated.
Thanks,
Brandon