Samselvaprabu
Samselvaprabu

Reputation: 18227

How to ensure that wi-fi is enabled or disabled using powershell?

We are using private network where ports are blocked by Firewall.

We will raise request to open ports for our machine IP address.

If wi-fi is enabled the system will have 2 IP address and if our connection routed through that IP address , we are unable to access our machines inside private network.

I would like to know whether any way is there in powershell to ensure the status (whether wi-fi is enabled/disabled).

Upvotes: 1

Views: 5681

Answers (3)

Vita
Vita

Reputation: 1

Or in case you need to know if wifi is connected from multiple remote machines you can list them in a file (in this case it is computers.txt) and run following script

$computers = Get-Content %PATH%\Computers.txt
$credentials = Get-Credential -Credential domain\username
     ForEach ($computer in $computers)
{
Write-Host "Computer Name: $computer"
Invoke-Command -ComputerName $computer -Credential $credentials -ScriptBlock {netsh wlan show interfaces} | select-string "State"
}

Upvotes: 0

CB.
CB.

Reputation: 60976

This one liner list all networkadapter matching wireless or wifi and that are enabled.

get-wmiobject -class win32_networkadapter -namespace root\CIMV2 | where-object {$_.Name -match "Wifi" -or $_.Name -match "wireless" -and $_.name -notmatch "Microsoft Virtual WiFi Miniport Adapter" -and $_.netenabled -eq $true}   | select description, netenabled

this for disable:

get-wmiobject -class win32_networkadapter -namespace root\CIMV2 | where-object {$_.Name -match "Wifi" -or $_.Name -match "wireless" -and $_.name -notmatch "Microsoft Virtual WiFi Miniport Adapter" -and $_.netenabled -eq $true } | % { $_.disable() }

this for enable:

get-wmiobject -class win32_networkadapter -namespace root\CIMV2 | where-object {$_.Name -match "Wifi" -or $_.Name -match "wireless" -and $_.name -notmatch "Microsoft Virtual WiFi Miniport Adapter" -and $_.netenabled -eq $false } | % { $_.enable() }

Upvotes: 3

Alex
Alex

Reputation: 23290

If you fire up a command prompt you can get info about WLAN with this:

netsh wlan show networks

Redirect output into a FIND command and you should be good to go

netsh wlan show networks | FIND "turned off" /I /C

WARNING: My windows isn't en-* localized so I'm not sure about the "turned off" thing, you might want to launch the command without the FIND part, in order to see the message it returns and adjust accordingly (if you launch the netsh command you'll see for yourself)

Upvotes: 1

Related Questions