Initial commit. Working and linked on PSGallery
This commit is contained in:
38
Public/Set-UnifiWlanPassword.ps1
Normal file
38
Public/Set-UnifiWlanPassword.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user