使用powershell将注册表值写入文本文件

问题描述 投票:0回答:1

我正在尝试将打开的笔记本字段路径从 OneNote 导出到文本文件中。 但无论我如何尝试,我都无法让它发挥作用。 我在这里遗漏了一些明显的东西吗?该注册表路径中肯定有值。

$registryPath = "HKCU:\SOFTWARE\Microsoft\Office\16.0\OneNote\OpenNotebooks"
$filePath = [Environment]::GetFolderPath("MyDocuments")
$outFile = Join-Path -Path $filePath -ChildPath "OneNotePaths.txt"

Get-ChildItem -Path $registryPath | ForEach-Object {
  $notebookPath = (Get-ItemProperty -Path $_.PsPath).Path
  Add-Content -Path $outFile -Value $notebookPath
}

编辑:脚本不知何故不会进入 ForeEach 循环,就好像在路径中找不到项目一样。

powershell registry
1个回答
0
投票

我不使用 PS 注册表提供程序,所以我从未想过枚举注册表项的值有多么棘手。

这就是它对您的情况的作用。我使用别名来使语句更容易阅读。如果您喜欢完整的陈述,您可以重新翻译它们:

gi $registryPath | %{ ac $outfile ( gpv $registryPath $_.Property ) }
© www.soinside.com 2019 - 2024. All rights reserved.