Pre-Flight Checks – AC Power Check

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.

 Function ZTIProcess()
 
     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 " & _
       Item.batterystatus, LogTypeInfo 
      Wscript.Quit(0)
    Else
      oLogging.CreateEntry "The computer is not plugged in.  Battery status is " & _
       Item.batterystatus, LogTypeError
      Wscript.Quit(1)
    End If    
Next

END FUNCTION

 

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’.

image

 

image

 

This post was contributed by Brad Tucker, a Senior Consultant with Microsoft Services, East Region, United States

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use

Z-ACPowerCheck.zip