While writing my last entry titled Pre-Flight Checks – Wireless Connectivity, I figured I would go ahead and post this script that does a pre-flight check to ensure the machine is plugged in to AC power. With the numbers of mobile devices becoming more and more prevalent in today’s enterprises, a check to ensure the device is plugged in prior to beginning imaging is crucial.
As I stated in my prior post (see above), MDT offers some checks, and even offers a wireless and AC power check within the UDI wizard. These last two checks, however, would require a touch for the wizard, as they are built in. Thus, this simple script to check the mobile device for AC power.
To check if the device is plugged in, I am looking at the Win32_Battery class. This class has an object called BatteryStatus that keeps track of, oddly enough, the status of the battery. The status we are looking for is ‘2’. This is recognized as ‘The system has access to AC so no battery is being discharged. However, the battery is not necessarily charging’. For more information on the Win32_Battery class, or BatteryStatus, click here.
iRetVal = Success
ZTIProcess = iRetval
Const scriptVersion = "1.0"
strComputer = "."
Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
' Query Win32_Battery from WMI
Set colBatteries = oWMI.ExecQuery("Select * From Win32_Battery")
oLogging.CreateEntry "Checking to determine if computer is plugged in...", LogTypeInfo
For each Item in colBatteries
If Item.batterystatus = 2 Then
oLogging.CreateEntry "The computer is plugged in. Battery status is " & _
oLogging.CreateEntry "The computer is not plugged in. Battery status is " & _
Adding to the Task Sequence
When adding this check to the task sequence, I add it to a standard command-line step and set it to run only if ISDESKTOP = ‘FALSE’ and ISSERVER = ‘FALSE’.
This post was contributed by Brad Tucker, a Senior Consultant with Microsoft Services, East Region, United States
Why did you not use the Property IsOnBattery
A very good question. The answer is, the original version of this script was originally written prior to MDT 2012. So, I just left it as is with minimal tweaks.
For everyone else, I am linking Michael Niehaus' blog on the new Gather improvements in MDT 2012.