Append value to Multi SZ Registry value using PowerShell

In the sample bellow the PowerShell script will append a service into RemoteAccessCheckExemptionList in registry. It also checks whether the value already exists there or not.

$subkey = 'SYSTEM\CurrentControlSet\Control\SecurePipeServers\SCM'
$value  = 'RemoteAccessCheckExemptionList'

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)
$key = $reg.OpenSubKey($subkey, $true)
$list = $key.GetValue($value)

if ($list -notcontains 'MyServiceName') {
  $list += 'MyServiceName'
}

$key.SetValue($value, [string[]]$list, 'MultiString')

Leave a Reply

Your email address will not be published. Required fields are marked *