The following script can be used in an SCCM or MDT upgrade task sequence to check if a laptop is connected to a charger. If the script detects that the laptop is not connected to a charger, it will prompt the user to connect the laptop to AC power.
$ChassisTypes = (Get-WmiObject -Class Win32_SystemEnclosure).ChassisTypes Switch($ChassisTypes) { 3 { $Chassis = "Desktop" } 4 { $Chassis = "Desktop" } 5 { $Chassis = "Desktop" } 6 { $Chassis = "Desktop" } 7 { $Chassis = "Desktop" } 8 { $Chassis = "Laptop" } 9 { $Chassis = "Laptop" } 10 { $Chassis = "Laptop" } 11 { $Chassis = "Laptop" } 12 { $Chassis = "Laptop" } 14 { $Chassis = "Laptop" } 15 { $Chassis = "Desktop" } 16 { $Chassis = "Desktop" } 18 { $Chassis = "Laptop" } 21 { $Chassis = "Laptop" } 23 { $Chassis = "Server" } 31 { $Chassis = "Laptop" } } If($Chassis -eq "Laptop") { Do { $PowerStatus = (Get-WmiObject -Class BatteryStatus -Namespace root\wmi -ErrorAction SilentlyContinue).PowerOnLine If($PowerStatus -ne $True) { $TSEnv = New-Object -ComObject "Microsoft.SMS.TsProgressUI" $TSEnv.CloseProgressDialog() $wshell = New-Object -ComObject Wscript.Shell $wshell.Popup("Please Connect AC Power - Click OK to Continue",0,"AC Power Check",0) } } Until($PowerStatus -eq $True) }
Carlton
Jose – thanks for posting this script. I’m in the middle of creating a Win7 to Win10 In-Place upgraded SCCM TS. Does your script need to be changed to reflect different models of laptops? (We use Dell Latitudes)
Jose Espitia
Hi Carlton,
It does not require any changes for different models. Essentially the script uses the chassis number in the BIOS to determine if the machine is a laptop, desktop or server. Unless Dell comes up with a new chassis, the script will work. As of right now, I have not had any issues with any of the Dell computers that I have tested with.
Marcel Moerings
Nice script, but how would you implement this in a task sequence? Run a command line, run a powershell script, use serviceUI? I tried by just running it as a powershell script, but it errors out of the TS.
Marcel Moerings
Found the error… the ServiceUI was looking for Powershell in the wrong location and threw a 0xfffffff error because of that. Fixed the path and now it works like a charm. Thanks for the script!
Jose Espitia
Great to hear Marcel!
Walter
So how exactly did you get this to work? I have struggled with this, mind if you sent a screen shot of your TS setup?
Thanks in advance.
Jose Espitia
Walter, you will need to use ServiceUI.exe to display the prompts with the TS.
More info here:
https://blogs.technet.microsoft.com/cameronk/2011/01/25/can-i-use-serviceui-exe-to-launch-other-programs-besides-the-udi-setup-wizard/