19
- September
2017
Posted By : Zeng Yinghua (Sandy)
Use PowerShell detect if Lenovo laptop is attached docks

Big thanks for Joe Parker (@joe_lenovo) gave us PnP ID of Lenovo ThinkPad Pro/Ultra docks.

ThinkPad Pro dock 40A1: USB\VID_17EF&PID_1012
ThinkPad Ultra 40A2: USB\VID_17EF&PID_1010

 

This a simple PowerShell script for detect if Lenovo laptops are attached to dock station, includes mechanical Lenovo ThinkPad docks and Lenovo USB 3.0 Pro/Ultra docks. 

$Manufacturer = (Get-WmiObject win32_computersystem).Manufacturer
if ($Manufacturer -like "Lenovo")
{
	try
	{
		$DeviceNames = Get-WmiObject Win32_USBControllerDevice -ErrorAction Stop | ForEach-Object { [wmi]($_.Dependent) } | Where-Object { $_.name -like "Displaylink*" -or $_.name -like "ThinkPad USB*dock*" -or $_.DeviceID -like "*usb\vid_17ef&pid_1010*" -or $_.DeviceID -like "*usb\vid_17ef&pid_1012*" } | Sort-Object Manufacturer, Description, DeviceID | Format-Table -GroupBy Manufacturer Description, Service, DeviceID, name
		$DeviceNames
	}
	catch
	{
		write-host $Error[0]
	}
}

or:

$Manufacturer = (Get-WmiObject win32_computersystem).Manufacturer
if ($Manufacturer -like "Lenovo")
{
	try
	{
		$DeviceNames = Get-PnpDevice -ErrorAction Stop | Where-Object { ($_.name -like "Displaylink*" -or $_.name -like "ThinkPad USB*dock*" -or $_.DeviceID -like "*usb\vid_17ef&pid_1010*" -or $_.DeviceID -like "*usb\vid_17ef&pid_1012*") -and $_.Status -like "OK" } | Sort-Object Manufacturer, Description, DeviceID | Format-Table -GroupBy Manufacturer Description, Service, DeviceID, name
		$DeviceNames
	}
	catch
	{
		write-host $Error[0]
	}
}

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.