Private/_LoadSettings.ps1
function _LoadSettings { [CmdletBinding()] [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Used by other functions.')] param ( [Parameter(Mandatory = $true)] [string]$File ) try { $Script:STTSettings = (Get-Content $File) -replace ('ObjectGuid', '_ObjectGuid') | ConvertFrom-Json } catch { $MessageSplat = @{ MessageText = 'Unable to load settings.' MessageIcon = 'Hand' ButtonType = 'OK' MessageTitle = 'Error' } _ShowMessageBox @MessageSplat } if ($STTSettings.DCSettings.UseAlternateCredentials) { if (Test-Path -Path $env:APPDATA\LoganShell\Stored.xml) { $Script:ADCredential = Import-Clixml -Path $env:APPDATA\LoganShell\Stored.xml Write-Verbose "Alt Username: $($ADCredential.Username)" $Script:SessionSplat = @{ Credential = $ADCredential } } else { Write-Host 'Unable to load alternate AD credentials. _LoadCredentials' } } else { $Script:SessionSplat = @{ } } if ($STTSettings.DCSettings.DomainController) { if ($STTSettings.DCSettings.UseAlternateCredentials) { $Script:GetObjectSplat = @{ Server = $STTSettings.DCSettings.DomainController Credential = $StoredCredential } } else { $Script:GetObjectSplat = @{ Server = $STTSettings.DCSettings.DomainController } } } else { $Script:GetObjectSplat = @{ } } if ($STTSettings.FeatureSettings.WhatsUpGold) { if (Test-Path $env:APPDATA\LoganShell\WUG.xml) { $Script:WUGCredential = Import-Clixml -Path $env:APPDATA\LoganShell\WUG.xml Write-Verbose "WUG Username: $($WUGCredential.Username)" } else { Write-Host 'Unable to load WUG credentials. _LoadCredentials' } } # Update UI # ADLookups if ($ADLookups) { $ADLookups_ConnectedDCStatusBarItem.Content = "Connected to: $($STTSettings.DCSettings.DomainController)" } if ($Options) { $Options_ModuleVersionLabel.Content = "Module Version: $($Module.Version)" } Write-Verbose ($SessionSplat | ConvertTo-Json) Write-Verbose ($GetObjectSplat | ConvertTo-Json) } |