I am trying to export 2 specific registry key (REG_SZ) to export through powershell.
Path to the registry: Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Intel\PSIS\PSIS_DECODER
Inside the above key, I have many keys, but I want to export specifically 2 keys to CSV and save it. I want the output CSV as below
Name | Value |
---|---|
Key 1 | Value 1 |
Key 2 | Value 2 |
$FindRegPath = HKLM:\SOFTWARE\Intel\PSIS\PSIS_DECODER
$Value1 = Get-ItemPropertyValue -Path $FindRegPath -Name "Key 1"
$Value2 = Get-ItemPropertyValue -Path $FindRegPath -Name "Key 2"
# Create CSV File with header
$outfile = "C:\temp\Outfile.csv"
$newcsv = {} | Select "Name","Value" | Export-Csv $outfile
How can I pass the Key and Value under the Name and Value inside the CSV?
There are 2 easy ways you can use to export the values, one is using Get-Item
to get the RegistryKey
instance and then use GetValue()
to get the property values:
$FindRegPath = 'HKLM:\SOFTWARE\Intel\PSIS\PSIS_DECODER'
$key = Get-Item $FindRegPath
# complete with the actual names here
$keys = 'Key 1', 'Key 2'
$keys | ForEach-Object {
[pscustomobject]@{
Name = $_
Value = $key.GetValue($_)
}
} | Export-Csv $outfile
The second way is very similar except you use Get-ItemProperty
and then get the values via dot notation:
$FindRegPath = 'HKLM:\SOFTWARE\Intel\PSIS\PSIS_DECODER'
$key = Get-ItemProperty $FindRegPath
# complete with the actual names here
$keys = 'Key 1', 'Key 2'
$keys | ForEach-Object {
[pscustomobject]@{
Name = $_
Value = $key.$_
}
} | Export-Csv $outfile
In both examples you need to consider that if the value is a byte array (byte[]
), you will need to manipulate it in order for it to be properly displayed in your CSV. For example, you could join the bytes with a delimiter:
...
...
$keys | ForEach-Object {
[pscustomobject]@{
Name = $_
Value = $key.GetValue($_) -join ',' # join the bytes with a comma
}
} | Export-Csv $outfile