Freigeben über


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

Comments

  • Anonymous
    January 01, 2003
    Maarten,

    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.
    http://blogs.technet.com/b/mniehaus/archive/2011/12/02/mdt-2012-new-feature-gather-improvements.aspx
  • Anonymous
    July 09, 2014
    Why did you not use the Property IsOnBattery
  • Anonymous
    February 17, 2015
    The comment has been removed