Bluetooth is a popular wireless technology that allows you to connect devices. Devices like smartphones, Keyboard, Mouse, and speakers can be connected using Bluetooth. If connected with Bluetooth they will not need any physical connection. Sometimes you might want to turn off your Bluetooth adapter. You might want to disable the Bluetooth adapter to conserve power. Also, restarting adapters can resolve most connection issues. In this article, we will see you how to turn on and off Bluetooth radio/adapter on Windows using PowerShell. But let's first see more about Powershell and Bluetooth.
Windows PowerShell is a task automation and configuration management framework from Microsoft. Powershell consists of a command-line shell and associated scripting language.
The scripting language used in PowerShell is based on the .NET framework. These functions can be implemented in scripts. Overall, PowerShell is an important tool for Windows administrators and developers. It provides a powerful and flexible way to automate and manage Windows-based systems.
Bluetooth is a wireless technology standard for exchanging data over short distances. Bluetooth uses a short wavelength of the frequency range between 2.4 to 2.485 GHz. To work Bluetooth builds a network known as personal area networks (PANs). Bluetooth is commonly used in a variety of devices that support wireless communication. It is used for connecting accessories and peripherals. Such accessories and peripherals include headphones, speakers, mouse, keyboards, and game controllers.
One of the key benefits of Bluetooth technology is that it allows for seamless and wireless communication. Using Bluetooth eliminates the need for cords and cables. That makes it easier to connect and manage multiple devices.
Control Bluetooth adapter using Powershell
To control the Bluetooth adapter from Powershell first, you need to enable custom script execution in Powershell. Powershell scripts have extension .ps1.
To enable the execution of unsigned scripts follow the following steps
Step 1: First, open PowerShell as administrator. Search for PowerShell in the Start menu and right-click on it. You will see an option called Run as administrator.
Step 2: After that, type the following command in PowerShell.
This above script allows the scripts to be run by all users.
Press y to confirm the execution of the above command.
This command allows scripts to be run by the current user without any restrictions.
Now let us see how we can enable and disable the Bluetooth adapter using PowerShell.
Step3: First, copy the following PowerShell script to a file. Then save the file with the extension .ps1, which is the extension for PowerShell.
A Windows device's Bluetooth radio can be managed with the help of this application written in PowerShell. To begin, a parameter called $BluetoothStatus is defined. This parameter can take either the value 'On' or the value 'Off.'
The script then checks to see if the Bluetooth service is operating, and if it isn't, it begins the process of starting it. After that, the application makes use of the System. Runtime. In order to communicate with Windows, the WindowsRuntime assembly is required. It does this by defining a function known as Await, which gives the script the ability to wait for asynchronous tasks that are returned by the API.
The script first uses the RequestAccessAsync method to ask for permission to access the Bluetooth radio, and then it uses the GetRadiosAsync method to obtain a list of all of the radios that are currently accessible. The script then applies a filter to the list of radios to locate the Bluetooth radio, and then uses the SetStateAsync method to change the status of the Bluetooth radio to the value that was specified in the $BluetoothStatus parameter. In the end, the script awaits the asynchronous task that was returned by the SetStateAsync function so that it can wait for the state to be changed.
Step 4: After saving the Script navigate the PowerShell terminal to the location where you save the script. This script accepts an argument while running as BluetoothStatus. And its value can be either on or off.
Step5: If you want to disable the Bluetooth device, type follows command in PowerShell.
Here bluetooth.ps1 is the name of the script that you saved in step 1.
Step6: If you want to disable the Bluetooth then replace the on with off on the above command.
Control Bluetooth adapter using Command Prompt
You can use Command Prompt and Batch file to enable and disable bluetooth in windows using following script.
Open notepad and paste down the following script and save it as enablebluetooth.bat .
now just run enablebluetooth.bat file by double clicking it and you will see bluetooth is enabled.
Open notepad and paste down the following script and save it as disablebluetooth.bat .
now just run disablebluetooth.bat file and you will see bluetooth is disabled.
In conclusion, turning on and off Bluetooth adapter on Windows using PowerShell and cmd script is easy and straightforward. The above script can be used to automate the process of enabling or disabling your Bluetooth adapter.