Solution is the same as proposed by @Diskoteket:
# Set-NetAdapterRadioPowerState.ps1
# credit to ben-n on superuser; adapted from https://superuser.com/a/1293303
[CmdletBinding()] Param (
[Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$WifiStatus
)
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]])
$wifi = $radios | ? { $.Kind -eq 'WiFi' }
[Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
Await ($wifi.SetStateAsync($WifiStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
Then run it from powershell 5 (C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe), in my system version 5.1.22000.282.
Don't use powershell 7 (latest version now 7.2.1, location C:\Program Files\PowerShell\7\pwsh.exe) because doesn't work.
Result now after activation (not connected to any wifi because it's connected by RJ45 which is priority):
.\Set-NetAdapterRadioPowerState.ps1 -WifiStatus On
Netsh WLAN show interfaces
There is 1 interface on the system:
Name : Wi-Fi
Description : Killer Wireless-n/a/ac Wireless Network Adapter
GUID : xx
Physical address : xx
Interface type : Primary
State : disconnected
Radio status : Hardware On
Software On
Hosted network status : Not available
Enable or disable with
.\Set-NetAdapterRadioPowerState.ps1 -WifiStatus On
.\Set-NetAdapterRadioPowerState.ps1 -WifiStatus Off
or if no arguments will ask.