Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to write a Power Shell script which will check the connection status of paired Bluetooth devices in a certain interval (15 sec) and if found the device is out of range then will lock the users system.

What I have tried:

In the following code I am not able to figure out how to list all the paired device.

Do
{
Start-Sleep -Seconds 15
$ListAllDevice = "Get the list of all paired Bluetooth Device"
$DeviceStatus = $ListAllDevice | Get-ItemProperty
$DeviceDetection = ($DeviceStatus).DeviceState
ForEach($IndDetection in $DeviceDetection)
  {
  If($IndDetection -eq 1)
   {
   Write-Host "device detected."
   }
  Else
   {
   rundll32.exe user32.dll,LockWorkStation
   }
  }

}
While((Get-Date).hour -le 18) 


While in other approach I also tried with the following code, but here Node status doesn’t change even if the connection out of range.

(Get-Device | Where-Object {$_.Name -like '*Lenovo*'}).NodeStatus
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900