Public/Radio/Set-RadioState.ps1

Function Set-RadioState {
  <#
.SYNOPSIS
  Turns a specific radio on or off.
.DESCRIPTION
  Accepts Radio objects (typically from the pipeline of Get-RadioState) and
  attempts to change the physical status to 'On' or 'Off'.
.PARAMETER SetState
  The desired target state. Use 'On' or 'Off'. (Supports autocomplete).
.PARAMETER Radios
  The Radio object to be modified. Accepts input via the pipeline.
.EXAMPLE
  Get-RadioState | Set-RadioState -SetState Off
  Get-RadioState | Where-Object Name -eq 'Wi-Fi' | Set-RadioState -SetState On
  Attempts to turn off all radios on the system.
.NOTES
  Some adapters (such as Mobile Broadband) may refuse the status change
  if they are managed elsewhere by the system. In such cases, the function will
  issue a warning rather than crashing.
#>

  param(
    [Parameter(Mandatory = $true)]$SetState,
    [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)][Alias("Radio")][Windows.Devices.Radios.Radio[]]$Radios,
    [int]$TimeoutMs = 10000
  )
  process {
    foreach ($R in $Radios) {
      $Task = $R.SetStateAsync($SetState)
      $ResultType = [Windows.Devices.Radios.RadioAccessStatus]
      $Status = Await -WinRtTask $Task -ResultType $ResultType -TimeoutMs $TimeoutMs
      if ($Status -ne 'Allowed') {
        Write-Warning "Radio $($R.Name) access status: $Status"
      }
    }
  }
}
Register-ArgumentCompleter -CommandName 'Set-RadioState' -ParameterName 'SetState' -ScriptBlock $ScriptBlockRadioState