SHARE
TWEET

bluetooth.ps1

userJSLQ Jun 3rd, 2019 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [CmdletBinding()] Param (
  2.     [Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$BluetoothStatus
  3. )
  4. If ((Get-Service bthserv).Status -eq 'Stopped') { Start-Service bthserv }
  5. Add-Type -AssemblyName System.Runtime.WindowsRuntime
  6. $asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
  7. Function Await($WinRtTask, $ResultType) {
  8.     $asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
  9.     $netTask = $asTask.Invoke($null, @($WinRtTask))
  10.     $netTask.Wait(-1) | Out-Null
  11.     $netTask.Result
  12. }
  13. [Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
  14. [Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
  15. Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
  16. $radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]])
  17. $radios
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top