Problem retrieving Value for DynamicSiteName from Registry using PS

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" 

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") 


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] 

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.


Propriétés

ID d'article : 2801452 - Dernière mise à jour : 24 janv. 2013 - Révision : 1

Commentaires