Turn Bluetooth status On/Off on Windows devices
  • 02 Feb 2024
  • 1 読む分
  • PDF

Turn Bluetooth status On/Off on Windows devices

  • PDF

The content is currently unavailable in Ja - 日本語. You are viewing the default English version.
記事の要約

The following PowerShell script helps the IT Admins to remotely turn On/Off the Bluetooth state on multiple managed Windows devices.

  1. Create a file on your desktop, for example, turn_on_off_bluetooth.ps1 and open it in a text editor like notepad++

  2. Copy the contents below to the file or click here to download the file.

    1. Set the $BluetoothStatus variable to "On" or "Off" based on your desired Bluetooth status.

      $BluetoothStatus = "Off" # Set this variable to "On" or "Off" based on your desired Bluetooth status
      
      If ((Get-Service bthserv).Status -eq 'Stopped') { Start-Service bthserv }
      Add-Type -AssemblyName System.Runtime.WindowsRuntime
      $asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
      Function Await($WinRtTask, $ResultType) {
          $asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
          $netTask = $asTask.Invoke($null, @($WinRtTask))
          $netTask.Wait(-1) | Out-Null
          $netTask.Result
      }
      [Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
      [Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
      Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
      $radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]])
      $bluetooth = $radios | ? { $_.Kind -eq 'Bluetooth' }
      [Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
      Await ($bluetooth.SetStateAsync($BluetoothStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
      
  3. Follow our guide to upload & publish the PowerShell script using Scalefusion Dashboard.

Please note that to use the PowerShell scripts, the Scalefusion MDM Agent Application must be installed on the device(s). Please follow our guide to publish and install the Scalefusion MDM Agent Application.

Notes:

  1. The scripts and their contents are sourced from various albeit authenticated Microsoft sources and forums.

  2. Please validate the scripts on a test machine before deploying them on all your managed devices.

  3. Scalefusion has tested these scripts, however, Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the incorrect usage of these scripts.


この記事は役に立ちましたか?