Monday, July 2, 2018

SCCM Configuration Item to Set or Append MultiString Registry Value

Sometimes you have a reg_multi_sz (aka MultiString value) registry key that you need to set in SCCM. Unfortunately version 1706 of configuration manager can only monitor but not remediate multistring registry values.

The way I've found to fix this is to use a short powershell script. With this script we'd like to detect and remediate the reg value. Also, if there's any existing entries in the list we may or may not want to overwrite them. In this case I wanted to append our new SharePoint site address to the AuthForwardServerList registry entry and not completely wipe out any existing settings.

Detection

$NewValue = 'https://yourserveraddress.com'
$path = "HKLM:\SYSTEM\CurrentControlSet\Services\WebClient\Parameters"
$name = 'AuthForwardServerList'

if (Test-Path $path) {
    $key = Get-Item $path
    if ($key.getvalue($name, $null) -ne $null) {
        $CurrentValue = Get-ItemPropertyValue $path $name
        if ($CurrentValue -contains $NewValue) {
            write-host 1
            }
            else {
                Write-Host 0
                }
        }
        else {
            write-host 0
            }
    }

Remediation

$NewValue = 'https://yourserveraddress.com'
$path = "HKLM:\SYSTEM\CurrentControlSet\Services\WebClient\Parameters"
$name = 'AuthForwardServerList'

if (Test-Path $path) {
    $key = Get-Item $path
    if ($key.getvalue($name, $null) -ne $null) {
        $CurrentValue = Get-ItemPropertyValue $path $name
        if ($CurrentValue -contains $NewValue) {
            }
            else {
                Set-ItemProperty -Path $path -Name $name -Value ($CurrentValue + $NewValue)
                }
        }
        else {
            New-ItemProperty -Path $path -Name $name -Value $server -PropertyType "MultiString"
            }
    }

If you wanted to overwrite and not append you could just drop the "$CurrentValue +" bit in the Set-ItemProperty line, setting it to only the new value.