Tag Archives: Remote Registry

Remote Registry with Powershell (PLUS: Create-ListBox function)

Until the powers of remoting arrive in Powershell v2, accessing a remote registry is a bit more cumbersome than a local registry. As you no doubt know, Powershell allows you to browse through the local registry as if it was a filesystem. The folling function should help you with accessing a remote registry:

function Enumerate-RemoteRegistryValues
{
 $ServerName = Read-Host “Server”
 $Hives = `
“ClassesRoot”,”CurrentConfig”,”CurrentUser”,`
“DynData”,”LocalMachine”,”PerformanceData”,”Users”
 $Hive = Create-ListBox -Items $Hives -Title “Select Registry Hive”`
 -Text “Select a remote registry hive to connect to:”
 $baseKeyName = Read-Host “Enter Key Name”
 $registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(`
[Microsoft.Win32.RegistryHive]::$Hive, $serverName)
 $baseKey = $registry.OpenSubKey($baseKeyName)
 $ValueNames = $baseKey.GetValueNames()
 $myCol = @()
 ForEach ($ValueName in $ValueNames)
 {
  $myObj = “” | Select Name, Value
  $myObj.Name = $ValueName
  $myObj.Value = $baseKey.GetValue($ValueName)
  $myCol += $myObj
 }
 return $myCol
}

Oh yeah!
One thing though. The real fanatics should have spotted it by now: The cmdlet Create-ListBox is not a native Powershell cmdlet. If fact, it is a function I created. It allows the user of the script to select a value from a collection of values using a sleek List Box. You should load this function before using the one above. Here’s how I did it: Continue reading

»crosslinked«