Private/Add-IgugaSetting.ps1
function Add-IgugaSetting { param( [Parameter(Mandatory = $true)] [string]$Key, [Parameter(Mandatory = $true)] [string]$Path, [Parameter(Mandatory = $true)] [ValidateNotNull()] [object]$Value ) switch ($type = $Value.GetType().Name) { 'securestring' { $setting = $Value | ConvertFrom-SecureString break } default { $setting = $Value } } if (Test-Path -LiteralPath $Path -PathType Leaf) { $storedSettings = Import-Clixml -Path $Path $storedSettings.Add($Key, @($type, $setting)) $storedSettings | Export-Clixml -Path $Path } else { $parentDir = Split-Path -Path $Path -Parent if (!(Test-Path -LiteralPath $parentDir)) { New-Item $parentDir -ItemType Directory > $null } @{$Key = @($type, $setting)} | Export-Clixml -Path $Path } } |