Public/Get-BluetoothState.ps1
|
function Get-BluetoothState { <# .SYNOPSIS Gets the current Bluetooth radio state. .OUTPUTS System.String .EXAMPLE Get-BluetoothState Returns the current Bluetooth state as On or Off. #> [CmdletBinding()] [OutputType([string])] Param() $output = Invoke-WindowsPowerShell -ScriptPath $script:BluetoothWinPSScriptPath -ScriptParameters @{ Action = 'Get' } $json = ($output | Where-Object { $_ -and $_.ToString().Trim() } | Select-Object -Last 1) if (-not $json) { throw 'Windows PowerShell bridge did not return a Bluetooth state payload.' } $result = $json | ConvertFrom-Json -ErrorAction Stop return [string]$result.State } |