32 lines
889 B
PowerShell
32 lines
889 B
PowerShell
function Get-UnifiConfigPath {
|
|
$dir = Join-Path $env:APPDATA 'UnifiCLI'
|
|
if (-not (Test-Path $dir)) {
|
|
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
|
}
|
|
Join-Path $dir 'config.json'
|
|
}
|
|
|
|
function Read-UnifiConfig {
|
|
$path = Get-UnifiConfigPath
|
|
if (Test-Path $path) {
|
|
Get-Content $path -Raw | ConvertFrom-Json -AsHashtable
|
|
} else {
|
|
$null
|
|
}
|
|
}
|
|
|
|
# Password is intentionally excluded — never written to disk
|
|
function Write-UnifiConfig {
|
|
param(
|
|
[Parameter(Mandatory)]
|
|
[hashtable]$Config
|
|
)
|
|
$safe = @{
|
|
ControllerUrl = $Config.ControllerUrl
|
|
Username = $Config.Username
|
|
DefaultSite = $Config.DefaultSite
|
|
SkipCertificateCheck = $Config.SkipCertificateCheck
|
|
}
|
|
$safe | ConvertTo-Json | Set-Content -Path (Get-UnifiConfigPath) -Encoding UTF8
|
|
}
|