PC Review Forums Newsgroups Windows XP Windows XP WMI Reboot specific systems WMI script

Reply

Reboot specific systems WMI script

 
Thread Tools Rate Thread
Old 20-06-2007, 05:20 PM   #1
WMI newbie
Junior Member
 
Join Date: Jun 2007
Posts: 1
Trader Rating: (0)
Question Reboot specific systems WMI script


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
WMI newbie is offline   Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off