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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Automatic Domain PC Reboots

Status
Not open for further replies.

dkel22

Programmer
Mar 31, 2004
49
US
Just a quick question, probably a simple on at that. I am fairly new to VBScript, but I have managed to create a script which will automatically run through a list of domain computers and reboot them if they are online. I just want to find an easy way to add a log of the script results so I can run it automatically via scheduled task and see the results. For example: COMPUTER name was rebooted. Here is the script I have created which runs as a scheduled task...Thanks in advance!!

On Error Resume Next

Dim strFilename
strFilename = "c:\pstools\computertest.txt"

Dim objFSO, objTS, strComputer
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(strFilename)
Do Until objTS.AtEndOfStream
strComputer = objTS.ReadLine

strComputer = UCase(strComputer)
Set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_PingStatus where address = '" & strComputer & "'")
For Each objItem in colItems
if objItem.StatusCode = 0 Then
PC= "ON"
Else
PC = "OFF"
End if
Next
If PC = "ON" then
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "oot\cimv2")

'Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
'Ensure that no user is logged on

For Each objItem in colItems
strdomuser = ""&objItem.UserName
dpos = InStr(strdomuser,"\")
strlen = Len(strdomuser)
strdomuser = Right(strdomuser,strlen-dpos)
strdomuser = UCase(strdomuser)
if strdomuser ="" Then
Set wshshl = WScript.CreateObject("wscript.Shell")

strrunme = "cmd /c c:\pstools\psshutdown.exe -m ""Your computer is being rebooted for nightly maintenance"" -f -r -t 15 \\" &strComputer
wshshl.run strrunme,0
end if
Next
End If

Loop
objTS.Close
 
I was able to figure it out on my own and got a little carried away with my text output to have a file for the failed reboots (offline or person still logged on) and a text file for the completed reboots.

This thread can be closed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top