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 
      oLogging.CreateEntry "The computer is not plugged in.  Battery status is " & _
       Item.batterystatus, LogTypeError
    End If    



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

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

Comments (3)
  1. Brad Tucker says:


    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.

  2. maarten says:

    Why did you not use the Property IsOnBattery

  3. vinay says:

    can some help me in writing a Script that determines if the device is on Battery or AC power

    Prompt user to plug device in if on Battery
    Do nothing if AC power is being use

Comments are closed.

Skip to main content