Reboot specific systems WMI script

Joined
Jun 20, 2007
Messages
1
Reaction score
0
I need to reboot only desktop systems post MS security patches install, and not laptops in our environment.
My first script attempt at performing this follows:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_ComputerSystem instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Name: " & objItem.Name
Next
IF ("Name: " <> "CNRS*") Then

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next

Else

End If


When deploying this script across the domain, both types of systems reboot, or the laptops reboot. I've even changed the following line:
IF ("Name: " <> "CNRS*") Then to IF ("Name: " = "CNPC*") Then
and the script still does not work properly. (CNRS = laptops, and CNPC = desktops)

I've even tried combining the following to scripts into one, but I'm just not certain how or where exactly to join them into one:

If isLaptop=False Then
WScript.Echo "not laptop"
Else
WScript.Echo "is laptop"
End If


Function isLaptop()
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery",,48)
For Each objItem in colItems
status=objItem.BatteryStatus
Next

If status<>"" Then
isLaptop=True
Else
isLaptop=False
End If
End Function

and

REM **Restarts a system without a dialog message box.**
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top