Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Problem retrieving Value for DynamicSiteName from Registry using PS


View products that this article applies to.

Symptoms

Retrieving DynamicSiteName Value from the registry in 


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters REG_SZ DynamicSiteName 

using Powershell e.g.

(Get-ItemProperty "HKLM:\System\CurrentControlSet\Services\Netlogon\parameters")."DynamicSiteName" 


This also happens on Windows 7 and Windows Server 2008 R2 whhen this update has been installed on the system

2506143 Description of Windows Management Framework 3.0 for Windows 7 SP1 and Windows Server 2008 R2 SP1
http://support.microsoft.com/kb/2506143/EN-US


The returned value ends with some unexpected characters

e.g.

"Default-First-Site-Name E" 

instead of 

"Default-First-Site-Name" 

↑ Back to the top


Cause

The netlogon Service writes this registry value and appends a NULL character plus a random character at the end.



This is not visible from standard applications like Regedit.exe, as most of the applications terminate the string with the ending NULL character. Since Update 2506143 the Framework returns the complete character Array.


Sample:

[Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("System\CurrentControlSet\Services\NetLogon\Parameters").GetValue("DynamicSiteName") 


↑ Back to the top


Resolution

Use this call to return the DynamicSiteName value limited with the ending NULL character


[Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("System\CurrentControlSet\Services\NetLogon\Parameters").GetValue("DynamicSiteName").Split([char]0)[0] 

↑ Back to the top


More Information

Newer versions of Windows will write the DynamicSiteName in the correct Format.

Note: There might be other REG_SZ values in the registry in malformed format, caused by other applications and tools. The workaround will always return the correct string value.


↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2801452
Revision : 1
Created on : 1/7/2017
Published on : 1/24/2013
Exists online : False
Views : 597