我正在尝试导出2个特定的注册表项(REG_SZ)以通过powershell导出。
注册表路径:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Intel\PSIS\PSIS_DECODER
在上面的密钥中,我有很多密钥,但我想将 2 个密钥导出到 CSV 并保存。我想要输出 CSV 如下
姓名 | 价值 |
---|---|
钥匙1 | 值1 |
钥匙2 | 值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
如何在 CSV 内的名称和值下传递键和值?
有两种简单的方法可以用来导出值,一种是使用
Get-Item
获取 RegistryKey
实例,然后使用 GetValue()
获取属性值:
$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
第二种方法非常相似,除了使用
Get-ItemProperty
并通过点表示法获取值:
$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
在这两个示例中,您需要考虑如果该值是字节数组 (
byte[]
),您将需要对其进行操作才能使其正确显示在 CSV 中。例如,您可以使用分隔符连接字节:
...
...
$keys | ForEach-Object {
[pscustomobject]@{
Name = $_
Value = $key.GetValue($_) -join ',' # join the bytes with a comma
}
} | Export-Csv $outfile