注册表管理(本地、远程)

 

查看项目属性:
Get-ItemProperty C:\Windows


查看注册表项:
Get-Item -path registry::HKLM\SYSTEM\CurrentControlSet\Control\CrashControl
Get-Item -path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl


查看注册表键值:
$CrashControl = Get-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl
$CrashControl.DumpFile


修改注册表键值:
Set-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl -Name CrashDumpEnabled -Value 1


新建注册表键值:
New-ItemProperty -path HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl -Name IgnorePagefileSize -PropertyType DWord -Value 1

通过将 Force 参数添加到任何 New-ItemProperty 命令,也可以覆盖预先存在的注册表条目值

PropertyType 值 含义
Binary 二进制数据
DWord 一个有效的 UInt32 数字
ExpandString 一个可以包含动态扩展的环境变量的字符串
MultiString 多行字符串
String 任何字符串值
QWord 8 字节二进制数据


删除注册表键值:
若要同时删除 PSHome 和 PowerShellPath 注册表条目,请使用 Remove-ItemProperty:
Remove-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PSHome
Remove-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion -Name PowerShellPath


清空注册表的值:
Clear-Item -Path HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run\PS
Clear-ItemProperty -Path HKLM:SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run -Name "VS2010" –PassThru

 

============================================================================

远程注册表管理

$MachineName = 'win2008'

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $MachineName)

#$true以编辑模式打开注册表键,不带$true则以只读模式打开
#$regKey = $reg.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", $true)


$regKey2 = $reg.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")

$j=$regkey2.GetSubKeyNames()

foreach ($w in $j)
{
$regKey3 = $reg.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$w")
$regkey3.getvalue("displayname") + $regkey3.getvalue("displayversion")
}

 

#$regkey.GetValueNames() #获取键值名称
#$regKey.CreateSubKey("VS2010") #新建子键
#远程修改注册表需要将远程计算机上的【Remote Registry】服务启动,否则会遇到错误

 

========================================================================

本地注册表管理

get-item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*

HKCU

[microsoft.win32.registry]::setvalue("HKEY_LOCAL_MACHINE\SOFTWARE\mysoftware","test","1""Dword")

 

判断注册表键值是否存在:

Get-ItemProperty hklm:\software\microsoft\windows\currentversion\run |Select-String "backinfo" -Quiet

#需要注意如果有诸如 "backinfo123"和“backinfo”的键值同时存在则无法判断正确,所以还是使用如下方法:

$MachineName = hostname
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $MachineName)
$regkey_backinfo = $reg.OpenSubKey("software\microsoft\windows\currentversion\run")
$backinfovalue = $regkey_backinfo.GetValue("BackInfo")
If ($backinfovalue -ne $null) #判断该键值是否为空
{
$backinfokind = $regkey_backinfo.GetValueKind("BackInfo")
If ($backinfovalue -eq "C:\Windows\Bi\Bi.exe" -and $backinfokind -eq "String")
{"Bi工具已安装成功"|Out-File $resultlog -Append}
Else {"Error: Bi工具未安装,请进行安装"|Out-File $resultlog -Append}
}

==============

判断注册表项是否存在:

Test-Path -path hklm:\software\microsoft\windows\currentversion\run


新建注册表项:
md hklm:\software\mysoftware
new-item -path hklm:\software -name mysoftware

新建注册表键值:
New-ItemProperty -path hklm:\software\microsoft\windows\currentversion\run -name backinfo3 -propertytype string -value c:\windows\binfo.exe

修改注册表键值:
set-itemproperty -path hklm:\software\mysoftware -name test1 -value 2

删除键值:
remove-itemproperty -path hklm:\software\mysoftware -name test1

删除KEY:
remove-item -path hklm:\software\mysoftware

 

posted on 2013-03-19 17:15  momingliu11  阅读(1078)  评论(0编辑  收藏  举报