我在使用 PowerShell 复制注册表子树时遇到问题,因为某些键包含斜杠(例如 HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\Languages\Language Services\C/C++
)
PS > Copy-Item -recurse HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\ZZZ
Copy-Item : The registry key at the specified path does not exist.
At line:1 char:1
+ Copy-Item -recurse HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\So ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (HKEY_CURRENT_US...odeExpansions\C:String) [Copy-Item], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand
Copy-Item : The registry key at the specified path does not exist.
At line:1 char:1
+ Copy-Item -recurse HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\So ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (HKEY_CURRENT_US...uage Services\C:String) [Copy-Item], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.CopyItemCommand
如何递归复制此类子树?
最佳答案
这是 Powershell 中的一个已知错误 - 它无法处理注册表路径中的正斜杠(适用于 get-childitem
,因此我希望它也会影响 copy-item
、重命名项目
、移动项目
等)。
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=238838&SiteID=99
并且在最新的 powershell (v4.0) 中仍然存在。
但是,您可以使用 powershell 运行 Reg DOS 命令: http://technet.microsoft.com/en-us/library/cc742057.aspx
reg.exe copy HKCU:\Software\Microsoft\VisualStudio\11.0\Languages HKCU:\ZZZ /s
关于powershell - 递归复制注册表子树,其中某些子项名称包含斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21223283/