26 January 2018

Checking if a laptop is docked

While writing this package for the BIOS updates on our systems to negate the Spectre and Meltdown, we decided we wanted all laptop systems to be docked. This is an extra precaution we are taking, along with deployment during the early hours of the morning, to minimize the possibility of the BIOS update being interrupted during the installation process by human error.

The first thing I found that designated if a system was docked was this registry key supposedly changing when a system was docked.

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\IDConfigDB\CurrentDockInfo\DockingState

I quickly realized this may have worked a long time ago, but it does not work anymore. The next thing I did was watch the event viewer logs. The only changes I noted there were with the ethernet when docked. The next thing I checked was the device manager and VoilĂ . The device manager changes when a laptop is docked. Specifically, the human interface devices add HID-compliant devices. I really thought the changes would be under system devices. Under the Human Interface Devices, I only included the devices that are labeled HID-compliant, in the HIDClass, are not vendor defined, and where the status of each filtered device is not OK, meaning it is not docked. This was all put in a one-liner that returns an exit code of 1 if any of the devices do not exist.

This one-liner is being used in the task sequence. If a return code of 1 is returned, meaning the system is not docked, the task sequence fails.

NOTE: For the systems this has been tested and run against, they are all Dell Latitudes. I do not have access to any other vendor systems to test against. If your company uses another vendor, you will need to possibly modify this script, or it may not work the same way. Also, it has been verified that this is different on varying models of Dell systems. I received a response on one of the Facebook groups saying he had to make some changes to the code for the Latitudes his company uses.


 powershell.exe "&{Get-PnpDevice | where-object { ($_.FriendlyName -like '*HID-compliant*') -and ($_.Class -eq 'HIDClass') -and ($_.FriendlyName -notlike '*vendor-defined device*')} | ForEach-Object { If ($_.Status -ne 'OK') { Exit 1 } } }"  

0 comments:

Post a Comment