Private/Options/_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
        WhatsUpGold = $Options_WUGIntegrationCheckBox.IsChecked
    }

    $WhatsUpGoldSettings = [PSCustomObject]@{
        WUGServerHostname = $Options_WUGServerTextBox.Text
        WUGServerPort     = '9644'
    }

    $EntraSettings = [PSCustomObject]@{
        TenantURL          = $Options_EntraTenantTextBox.Text
        EntraConnectServer = $Options_ConnectServerTextBox.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
        }
        UseAlternateCredentials = $Options_CredentialsAlternateCheckBox.IsChecked
    }

    $Settings = [PSCustomObject]@{
        Theme               = if ($Options_DarkThemeRadioButton.IsChecked) {
            'Dark'
        }
        elseif ($Options_VioletThemeRadioButton.IsChecked) {
            'Violet'
        }
        elseif ($Options_LightThemeRadioButton.IsChecked) {
            'Light'
        }
        else {
            'Light'
        }

        FeatureSettings     = $FeatureSettings
        WhatsUpGoldSettings = $WhatsUpGoldSettings
        EntraSettings       = $EntraSettings
        SCCMSettings        = $SCCMSettings
        ObjectsSettings     = $ObjectsSettings
        DCSettings          = $DCSettings
        SettingsVersion     = '5'
    }

    try {
        $Settings | ConvertTo-Json | Out-File "$($Path)Settings.json"
    }
    catch {
        $Options_SavingTextBlock.Text = 'Saving failed.'
        break
    }

    $Options_SavingTextBlock.Text = 'Settings saved.'

    $Script:STTSettings = _LoadSettings -File $env:APPDATA\LoganShell\Settings.json -ErrorAction Stop
}