Private/_SaveSettings.ps1
function _SaveSettings { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [ValidateScript({ Test-Path $_ })] [string] $Path ) $FeatureSettings = [PSCustomObject]@{ Entra = $Options_EntraIDCheckBox.IsChecked Exchange = $Options_ExchangeIntegrationCheckBox.IsChecked SCCM = $Options_SCCMIntegrationCheckBox.IsChecked } $EntraSettings = [PSCustomObject]@{ TenantURL = $Options_EntraTenantTextBox.Text EntraConnectServer = $Options_EntraConnectServerTextBox.Text } $SCCMSettings = [PSCustomObject]@{ # TODO do i need these if statements? the initial settings and first run should catch this. SCCMServerHostname = if ($Options_SCCMServerTextBox.Text) { $Options_SCCMServerTextBox.Text } else { 'Not Defined' } SCCMDefaultCollection = if ($Options_SCCMCollectionComboBox.Text) { $Options_SCCMCollectionComboBox.Text } else { 'All Systems' } } $ObjectsSettings = [PSCustomObject]@{ ObjectStorageFolder = $Options_ObjectCacheTextBox.Text } $DCSettings = [PSCustomObject]@{ DomainController = if ($Options_DCComboBox.Text) { $Options_DCComboBox.Text } else { # This is defined in the pre-run checks $PDC.Name } } $Settings = [PSCustomObject]@{ Theme = if ($Options_DarkThemeRadioButton.IsChecked) { 'Dark' } elseif ($Options_VioletThemeRadioButton.IsChecked) { 'Violet' } elseif ($Options_LightThemeRadioButton.IsChecked) { 'Light' } else { 'Light' } FeatureSettings = $FeatureSettings EntraSettings = $EntraSettings SCCMSettings = $SCCMSettings ObjectsSettings = $ObjectsSettings DCSettings = $DCSettings SettingsVersion = '2' } try { $Settings | ConvertTo-Json | Out-File "$($Path)Settings.json" } catch { $Options_SavingTextBlock.Text = 'Saving failed.' break } $Options_SavingTextBlock.Text = 'Settings saved.' # $MessageSplat = @{ # MessageText = 'Restart ServerTeamTools to use the newly saved settings.' # MessageIcon = 'Asterisk' # ButtonType = 'OK' # MessageTitle = 'Restart function' # } # _ShowMessageBox @MessageSplat $Script:STTSettings = _LoadSettings -File $env:APPDATA\LoganShell\Settings.json -ErrorAction Stop } |