userJSLQ

bluetooth.ps1

Jun 3rd, 2019
196
0
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
Add Comment
Please, Sign In to add comment