PowerShell – Verify if Device is Connected

email me

This will check to see if a device is connected to computer

clear-host

# list out all devices - just for troubleshooting purposes
Get-PnpDevice -PresentOnly

# which device to test
$TestDevice = "Bluetooth"

# test device
If (Get-PnpDevice -PresentOnly -FriendlyName $TestDevice) {write-host "TRUE"} Else {Write-host "FALSE"} -silentlycontinue


Notes

$ErrorActionPreference = ‘Stop’
$ErrorActionPreference= ‘silentlycontinue’

try
{
Main code
}
catch
{
Error handling
}

more…