Guest User

InstallWifi.ps1

a guest
Jan 9th, 2026
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.51 KB | None | 0 0
  1. # Fill in mandatory details for the WiFi network
  2. $WirelessNetworkSSID = '<wifi name>'
  3. $WirelessNetworkPassword = '<password>'
  4. $Authentication = 'WPA2-Personal' # Could be WPA2
  5. $Encryption = 'CCMP'
  6.  
  7. # Create the WiFi profile, set the profile to auto connect
  8. $WirelessProfile = @'
  9. <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
  10.     <name>{0}</name>
  11.     <SSIDConfig>
  12.         <SSID>
  13.             <name>{0}</name>
  14.         </SSID>
  15.     </SSIDConfig>
  16.     <connectionType>ESS</connectionType>
  17.     <connectionMode>auto</connectionMode>
  18.     <MSM>
  19.         <security>
  20.             <authEncryption>
  21.                 <authentication>{2}</authentication>
  22.                 <encryption>{3}</encryption>
  23.                 <useOneX>false</useOneX>
  24.             </authEncryption>
  25.             <sharedKey>
  26.                 <keyType>passPhrase</keyType>
  27.                 <protected>false</protected>
  28.                 <keyMaterial>{1}</keyMaterial>
  29.             </sharedKey>
  30.         </security>
  31.     </MSM>
  32. </WLANProfile>
  33. '@ -f $WirelessNetworkSSID, $WirelessNetworkPassword, $Authentication, $Encryption
  34.  
  35. # Create the XML file locally
  36. $random = Get-Random -Minimum 1111 -Maximum 99999999
  37. $tempProfileXML = "$env:TEMP\tempProfile$random.xml"
  38. $WirelessProfile | Out-File $tempProfileXML
  39.  
  40. # Add the WiFi profile and connect
  41. Start-Process netsh ('wlan add profile filename={0}' -f $tempProfileXML)
  42.  
  43. #Set connection mode to auto
  44. Start-Process netsh ('wlan set profileparameter name="{0} connectionmode=auto"' -f $WirelessNetworkSSID)
  45.  
  46. # Connect to the WiFi network - only if you need to
  47. Start-Process netsh ('wlan connect name="{0} connectionmode=auto"' -f $WirelessNetworkSSID)
  48.  
Advertisement
Add Comment
Please, Sign In to add comment