当前位置:首页 >> 脚本专栏

PowerShell注册表操作命令总结

你可以像导航文件系统那样来访问注册表,PowerShell把文件系统和注册表都当作层次信息系统来处理。注册表中的键对应于文件系统的目录,但是键对应的值和文件系统中的文件不是非常类似。相反的,它们显示在属性栏,被以键的属性来管理。
复制代码 代码如下:
PS C:\> Cd HKCU:
PS HKCU:\> dir

    Hive: HKEY_CURRENT_USER

Name                           Property
----                           --------
AppEvents
Console                        ColorTable00           : 0
                               ColorTable01           : 8388608
                               ColorTable02           : 32768
                               ColorTable03           : 8421376
                               ColorTable04           : 128
                               ColorTable05           : 8388736
                               ColorTable06           : 32896
                               ColorTable07           : 12632256
                               ColorTable08           : 8421504
                               ColorTable09           : 16711680
                               ColorTable10           : 65280
                               ColorTable11           : 16776960
                               ColorTable12           : 255
                               ColorTable13           : 16711935
                               ColorTable14           : 65535
                               ColorTable15           : 16777215
                               CursorSize             : 25
                               EnableColorSelection   : 0
                               ExtendedEditKey        : 0
                               ExtendedEditKeyCustom  : 0
                               FontFamily             : 0
                               FontSize               : 0
                               FontWeight             : 0
                               FullScreen             : 0
                               HistoryBufferSize      : 50
                               HistoryNoDup           : 0
                               InsertMode             : 1
                               LoadConIme             : 1
                               NumberOfHistoryBuffers : 4
                               PopupColors            : 245
                               QuickEdit              : 0
                               ScreenBufferSize       : 19660880
                               ScreenColors           : 7
                               TrimLeadingZeros       : 0
                               WindowSize             : 1638480
                               WordDelimiters         : 0
                               CurrentPage            : 0
Control Panel
Environment                    TEMP : C:\Users\mosser\AppData\Local\Temp
                               TMP  : C:\Users\mosser\AppData\Local\Temp
EUDC
Identities                     Identity Ordinal : 1
                               Migrated7        : 1
                               Last Username    : Main Identity
                               Last User ID     : {563ED914-095C-4B36-9D01-743D0C2AF679}
                               Identity Login   : 622675
                               Default User ID  : {563ED914-095C-4B36-9D01-743D0C2AF679}
Keyboard Layout
Network
Printers
Software
System
Volatile Environment           LOGONSERVER   : \\DC.PSTips.Net
                               USERDNSDOMAIN : PSTips.Net
                               USERDOMAIN    : PSTips.Net
                               USERNAME      : mosser
                               USERPROFILE   : C:\Users\mosser
                               HOMEPATH      : \Users\mosser
                               HOMEDRIVE     : C:
                               APPDATA       : C:\Users\mosser\AppData\Roaming
                               LOCALAPPDATA  : C:\Users\mosser\AppData\Local


下面的列出了访问注册表所需的所有命令。
复制代码 代码如下:
命令                 描述
Dir, Get-ChildItem 列出键的内容
Cd, Set-Location 更改当前(键)目录
HKCU:, HKLM:         预定义的两个重要注册表根目录虚拟驱动器
Get-ItemProperty 读取键的值
Set-ItemProperty 设置键的值
New-ItemProperty 给键创建一个新值
Clear-ItemProperty 删除键的值内容
Remove-ItemProperty 删除键的值
New-Item, md         创建一个新键
Remove-Item, Del 删除一个键
Test-Path         验证键是否存在

注意:注册表几乎存储了Windows的核心配置。所以这也是它为什么成为我们用来读取和更改Windows配置的重要位置。因此乱搞或者误删非常危险,可能造成Windows不能启动。

文章出处:http://www.pstips.net/the-registry.html