title: How to switch WiFi state on/off with PowerShell & Windows 10?
body: <p>I have a tiny <code>.ps1</code> script which switches a network connection between Ethernet and WiFi. My script works well. I now want to know how to switch off WiFi without disabling the underlying network adapter. </p>
  
  <p><strong>Here is my existing script:</strong></p>
  
  <pre><code>$lanState = Get-NetAdapter -Name MyEthernetPort | where status -EQ 'up'
  
  if ( $lanState )
  {
      write-host 'Enabled... Disable now'
      Get-NetAdapter -Name MyEthernetPort | ? status -NE disabled | Disable-NetAdapter -Confirm:$false
      # TODO switch on wifi
      netsh wlan connect name=SM-GUEST
  }
  else
  {
      Write-Host 'Disabled... Enable now'
      Get-NetAdapter -Name MyEthernetPort | ? status -EQ disabled | Enable-NetAdapter -Confirm:$false
      # TODO switch off wifi
      netsh wlan disconnect
  }
  </code></pre>
  
  <p>I haven't been able to find any guidance on how to switch off WiFi via PowerShell (in the same way as it would occur if you clicked the button in the Windows 10 info center). All scripts that I've found just disable the underlying adapter, which is not what I want. </p>
  
  <p>Can anybody suggest how to access this functionality from PowerShell?</p>