powershell 在Windows上添加新的WiFi Profil(Powershell)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 在Windows上添加新的WiFi Profil(Powershell)相关的知识,希望对你有一定的参考价值。

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
	<name>NEW-PROFILE-NAME</name>
	<SSIDConfig>
		<SSID>
			<hex>SOME-HEX-CODE</hex>
			<name>WIRELESS-NETWORK-NAME</name>
		</SSID>
	</SSIDConfig>
	<connectionType>ESS</connectionType>
	<connectionMode>manual</connectionMode>
	<MSM>
		<security>
			<authEncryption>
				<authentication>WPA2PSK</authentication>
				<encryption>AES</encryption>
				<useOneX>false</useOneX>
			</authEncryption>
			<sharedKey>
				<keyType>passPhrase</keyType>
				<protected>false</protected>
				<keyMaterial>SCRET-PASSWORD-COMES-HERE</keyMaterial>
			</sharedKey>
		</security>
	</MSM>
</WLANProfile>
<#
.SYNOPSIS
 
.DESCRIPTION
	This script add WiFi Profile to (first) WLAN Adapter. Password in profile should be in plain text
 
.PARAMETER <Parameter_Name>
 
.INPUTS
	Path to WiFi Profile
 

.NOTES
    Version:        1.0
    Author:	Robert Rajakone
    Creation Date:	23. August 2013
    Purpose/Change: Initial script development
 
.EXAMPLE
	Add_Wifi_Profile.ps1 "\\domain.local\netlogon\scripts\wifi_profile.xml"
 
#>

Param(
	[Parameter(Mandatory=$true)] [string] $PathToProfileXML
)
Write-Host ""
Write-Host ""
Write-Host ""

$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if(-not($IsAdmin)){
	throw "Current User has no administrative rights. Restart script as administrator."
}
		


if(-not(Test-Path $PathToProfileXML)){
	throw "Profile file do not exist at give path: $PathToProfileXML"
}

$strDump=netsh wlan show interfaces
$strNameDump = $strDump[3]
$Result = [regex]::match($strNameDump, "^.*Name.*: (.*)$")
$WirlessAdapterName = $Result.Groups[1].Value

if($WirlessAdapterName){
	Write-Host "Adapter found: $WirlessAdapterName"	
	Write-Host ""
	Write-Host "Trying to add Profile"
	Write-Host $PathToProfileXML
	netsh wlan add profile filename=$PathToProfileXML interface="$WirlessAdapterName"
}else{
	Write-Host "No WiFi Adapter found" -ForegroundColor Red
}

以上是关于powershell 在Windows上添加新的WiFi Profil(Powershell)的主要内容,如果未能解决你的问题,请参考以下文章

如果 IP 地址已配置,如何使用 Powershell 脚本检查

windows powershell 如何进入文件目录

使用 powershell 添加新的 AD 用户不会使用 AD LDS 添加 samaccountname

Powershell:在 Windows 10 中获取 GPS 坐标 - 使用 Windows 位置 API?

如何在windows下写shell脚本

powershell 通过PowerShell添加Windows功能