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