PowerShell for Windows Admins

Jan 13 2011   1:57PM GMT

Registry data types



Posted by: Richard Siddaway
Tags:
PowerShell v2
Registry

 

One point I didn’t cover in my series on working with the registry was how to get the type of a registry value.

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
$regtype = DATA {
ConvertFrom-StringData -StringData 
@’
1 = REG_SZ
2 = REG_EXPAND_SZ
3 = REG_BINARY
4 = REG_DWORD
7 = REG_MULTI_SZ
‘@

}
$HKLM = 2147483650
$key = "SOFTWARE\Microsoft\Windows\CurrentVersion"
$computer="."
$reg = [wmiclass]"\\$computer\root\default:StdRegprov"
$data = $reg.EnumValues($HKLM, $key)
$x = ($data.snames).Length
for ($i=0; $i -le $x; $i++){"{0,-30} {1}" -f
 
  $(
$data.snames[$i]), $regtype["$($data.types[$i])"] 
}

The easiest way is to use the EnumValues() method.  This returns integer values for the type.

Define a hash table that contains the integer and its meaning. Define the hive and the key. Create an instance of StdRegProv and invoke the EnumValues method. Loop through the returned values and use a formatted string to display the results

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: