# Script to show a list of connected Bluetooth devices on Windows 10/11

Bluetooth devices enable wireless communication with other compatible devices via Bluetooth technology. They seamlessly connect to devices through the built-in Bluetooth functionality.

With the use of Hexnode’s [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) action, IT administrators will be able to run the script given below to show connected Bluetooth devices to Windows endpoints managed in your workplace environment. This aids IT administrators in monitoring unauthorized Bluetooth connections, allowing them to take necessary actions to mitigate potential network risks that could harm the company’s network.

 Disclaimer:The sample scripts provided below are adapted from third-party open-source sites.

 

PowerShell script to show all Bluetooth devices currently connected 
--------------------------------------------------------------------

PowerShell script to show all Bluetooth devices currently connected

\# Get the list of connected Bluetooth devices $bluetoothDevices = Get-WmiObject -Query "SELECT \* FROM Win32\_PnPEntity WHERE PNPClass = 'Bluetooth'" | Select-Object Name # Display the list of Bluetooth devices foreach ($device in $bluetoothDevices) { Write-Host "Bluetooth Device: $($device.Name)" } 

   1

2

3

4

5

6

  \# Get the list of connected Bluetooth devices 

$bluetoothDevices = Get-WmiObject -Query "SELECT \* FROM Win32\_PnPEntity WHERE PNPClass = 'Bluetooth'" | Select-Object Name

\# Display the list of Bluetooth devices 

foreach ($device in $bluetoothDevices) {

 Write-Host "Bluetooth Device: $($device.Name)"

} 

   

 

  

The PowerShell script provided fetches and lists the names of connected Bluetooth devices on a Windows system. It uses the **Get-WmiObject** cmdlet in PowerShell to access information from the Windows Management Instrumentation (WMI) repository. The cmdlet fetches instances of WMI classes or information about the available WMI classes. The command targets the **Win32\_PnPEntity** class in WMI which represents the Plug and Play devices on the Windows system. By querying this class, it selectively captures information about devices categorized as *‘Bluetooth’*. This data is stored in the **$bluetoothDevices** variable for further processing. Subsequently, a foreach loop iterates through the devices, displaying their names using the Write-Host command.

Batch script to show all Bluetooth devices currently connected
--------------------------------------------------------------

Batch script to show all Bluetooth devices currently connected

@echo off setlocal enabledelayedexpansion rem Get the list of connected Bluetooth devices for /f "tokens=\*" %%a in ('wmic path Win32\_PnPEntity where "PNPClass='Bluetooth'" get Name /format:list ^| findstr /r /c:"^Name="') do ( rem Extract device name set "line=%%a" set "deviceName=!line:~5!" rem Display the list of Bluetooth devices echo Bluetooth Device: !deviceName! ) 

   1

2

3

4

5

6

7

8

9

10

  @echo off 

setlocal enabledelayedexpansion 

rem Get the list of connected Bluetooth devices 

for /f "tokens=\*" %%a in ('wmic path Win32\_PnPEntity where "PNPClass='Bluetooth'" get Name /format:list ^| findstr /r /c:"^Name="') do (

 rem Extract device name 

 set "line=%%a"

 set "deviceName=!line:~5!"

 rem Display the list of Bluetooth devices 

 echo Bluetooth Device: !deviceName!

) 

   

 

  

This batch script is designed to identify and list connected Bluetooth devices on a Windows system. It utilizes the **wmic** command to query the **Win32\_PnPEntity** class, filtering the devices categorized as *‘Bluetooth’*, and retrieves their names in list format. The output is then filtered using findstr to include only lines starting with *‘Name=’*. Within a loop, each line is processed to extract the device name, which is displayed with a prefix indicating that it is a Bluetooth device.

What happens at the device end?
-------------------------------

After the execution of the script, a list of all connected Bluetooth devices can be seen from the Action History of the Windows device in the Hexnode portal. If the Windows device’s Bluetooth is either disabled or no Bluetooth devices are connected, the script will list Bluetooth adapters or modules integrated into the computer’s hardware. These components facilitate wireless communication between Windows devices and other Bluetooth-enabled devices.

[![A list of all connected Bluetooth devices will be shown in the Action History of the Windows 10/11 device](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/03/The-list-of-all-connected-Bluetooth-devices-on-the-Windows-10-or-11-devices-can-be-shown.png "The list of all connected Bluetooth devices on the Windows 10 or 11 devices can be shown")](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2024/03/The-list-of-all-connected-Bluetooth-devices-on-the-Windows-10-or-11-devices-can-be-shown.png)

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.