Reputation: 1112
Similar posts such as this one or this one explain how to get a remote registry key, but it assumes that you already know the name of the value that you are interested in. If you run
Get-ItemProperty "HKLM:\Software\MySoftware"
It will return all properties and their corresponding values, but Get-ItemProperty doesn't work for remote machines. If you want to do the same for a remote registry key you can use the [Microsoft.Win32.RegistryKey] approach but that is only half the answer. As an example:
$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $myServer)
$RegKey= $Reg.OpenSubKey("SOFTWARE\\MySoftware")
$RegKey will become a System.MarshalByRefObject. This means that it is not the actual key but rather just opens up the ability to continue asking for more information from that key. Using the $RegKey.GetValue() requires you to know the value you want to fetch, but what if you want to fetch all values for the key but you don't know how many values there are, or their names? How would you go about doing this?
Upvotes: 0
Views: 3576
Reputation: 1112
After you have opened the $RegKey you can use the following:
$RegKey.GetValueNames()
This will produce a list of all item properties and their values. You can then loop through that list with a foreach to retrieve the value for all of the item properties like:
foreach($ItemProperty in $RegKey.GetValueNames()){
$RegKey.GetValue($ItemProperty)
}
Bonus: If you want to export this to, say, a CSV file you can create a custom PS object and export this to a CSV file as follows:
foreach($ItemProperty in $RegKey.GetValueNames()){
$myObject = [PSCustomObject]@{
ItemProperty = $ItemProperty
Value = $RegKey.GetValue($ItemProperty)
} | Export-Csv "yourpath\yourfile.csv" -Append -Delimiter "|" -NoTypeInformation
}
Upvotes: 0