PowerShell创建注册表DWORD后显示异常,如何刷新及是否正常?
注册表操作显示不一致问题及刷新方法
为解决RSAT工具安装时出现的Add-WindowsCapability失败,错误代码0x800f0954问题,执行以下PowerShell命令创建新的DWORD值:
New-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing -Name RepairContentServerSource -Type dword -Value 2 # 命令输出: RepairContentServerSource : 2 PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies PSChildName : Servicing PSDrive : HKLM PSProvider : Microsoft.PowerShell.Core\Registry
执行ls HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing(ls是Get-ChildItem的别名)命令无任何输出:
ls HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing # 无输出
但执行gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing(gp是Get-ItemProperty的别名)命令,能看到CountryCode和新建的RepairContentServerSource值:
gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing # 命令输出: CountryCode : FR RepairContentServerSource : 2 PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Servicing PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies PSChildName : Servicing PSDrive : HKLM PSProvider : Microsoft.PowerShell.Core\Registry
另外,执行组合命令(ls HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies | Out-String -Stream | sls RepairContentServerSource).ToString()也能查到该DWORD值:
(ls HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies | Out-String -Stream | sls RepairContentServerSource).ToString() # 命令输出: RepairContentServerSource : 2
问题
- 如何在PowerShell中刷新注册表?
- 这种不同命令显示结果不一致的现象是否正常?
内容的提问来源于stack exchange,提问作者SebMa
相关产品推荐
相关产品推荐

