39 lines
1.2 KiB
PowerShell
39 lines
1.2 KiB
PowerShell
function Set-UnifiWlanPassword {
|
|
[CmdletBinding(SupportsShouldProcess)]
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[string]$Ssid,
|
|
|
|
[string]$Site,
|
|
|
|
# If omitted, a SecureString prompt will appear
|
|
[SecureString]$NewPassword
|
|
)
|
|
|
|
if (-not $script:UnifiSession) {
|
|
Write-Error "Not connected. Run Connect-UnifiController first."
|
|
return
|
|
}
|
|
|
|
$siteId = Resolve-UnifiSite $Site
|
|
|
|
$result = Invoke-UnifiRequest -Endpoint '/rest/wlanconf' -Site $siteId
|
|
$wlan = $result.data | Where-Object { $_.name -eq $Ssid } | Select-Object -First 1
|
|
|
|
if (-not $wlan) {
|
|
Write-Warning "No WLAN named '$Ssid' found on site '$siteId'."
|
|
return
|
|
}
|
|
|
|
if (-not $NewPassword) {
|
|
$NewPassword = Read-Host -Prompt "New password for '$Ssid'" -AsSecureString
|
|
}
|
|
|
|
$plainText = ConvertFrom-SecureString -SecureString $NewPassword -AsPlainText
|
|
|
|
if ($PSCmdlet.ShouldProcess("WLAN '$Ssid' on site '$siteId'", 'Set password')) {
|
|
Invoke-UnifiRequest -Method PUT -Endpoint "/rest/wlanconf/$($wlan._id)" -Site $siteId -Body @{ x_passphrase = $plainText }
|
|
Write-Host "Password updated for '$Ssid' on site '$siteId'." -ForegroundColor Green
|
|
}
|
|
}
|