title: Running a PowerShell script as administrator without typing in passwords
body: <p>I wrote a script that will switch between having a computer connect via Wi-Fi or wired Internet simply by running a batch file. I wrote this because I don't like having to type in my username and password to switch between the two every time.</p>
  
  <p>NOTE: I HAVE to have UAC enabled so unfortunately just turning it off isn't an option.</p>
  
  <p>It looks at the status of the wireless adapter. If it is currently enabled, it will turn off the wireless adapter and enable the wired adapter. If the wireless is not enabled, it will enabled and disable the wired. This is the code.</p>
  
  <pre><code>$adapter = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName . | Where-Object {$_.ServiceName -ne "hamachi"}
  function wirelessOn
  {
      $wireless = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}
      $wireless.Disable()
      $wired = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*gigabit*"}
      $wired.Enable()
  }
  
  function wirelessOff
  {
      $wired = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*gigabit*"}
      $wired.Disable()
      $wireless = Get-WmiObject -Class Win32_NetworkAdapter | Where-Object {$_.Name -like "*Wireless*"}
      $wireless.Enable()
  }
  
  switch -wildcard ($adapter.description){
      "*wireless*" {
          wirelessOn
      }
      "*gigabit*" {
          wirelessOff
      }
  }
  </code></pre>
  
  <p>Unfortunately, this script only functions properly if run as administrator, thus the whole reason I wrote it is moot. Is there a way I can have this elevate to administrator privileges without me having to do anything?</p>