PC Review
Forums
Newsgroups
Windows XP
Windows XP WMI
Reboot specific systems WMI script
Forums
Newsgroups
Windows XP
Windows XP WMI
Reboot specific systems WMI script
![]() |
Reboot specific systems WMI script |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Junior Member
|
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 |
|
|
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

