专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

The concept of a drive in PowerShell is not about physical drives, but about representing any data store as a consistent interface. Using the right provider you can even access  the registry as if it was a file structure.

PowerShell中的驱动器概念与物理驱动器无关,而是与将任何数据存储表示为一致的接口有关。 使用正确的提供程序,您甚至可以像使用文件结构一样访问注册表。

在外壳中导航 (Navigating In The Shell)

Open PowerShell by typing PowerShell into the search bar and pressing enter.

在搜索栏中键入PowerShell,然后按Enter,以打开PowerShell。

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

When PowerShell opens, type:

打开PowerShell后,键入:

cd HKCU:

CD HKCU:

To change to the HKEY_CURRENT _USER hive.

更改为HKEY_CURRENT _USER配置单元。

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

The keys in the registry are like folders. However, key values don’t behave like files. Instead, they are managed as properties of keys and are displayed in the property column.  To see a list of keys you can simply run:

注册表中的项就像文件夹。 但是,键值的行为不像文件。 而是将它们作为键的属性进行管理,并显示在属性列中。 要查看键列表,您可以简单地运行:

Dir

迪尔

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

To do more with the keys its easiest to create a variable for the key. Lets make a variable called key, for the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer key.

要对键进行更多操作,最容易为键创建变量。 让我们为HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer**创建一个称为key的变量。

$key = Get-Item HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer

$ key =获取项目HKCU:\ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

Next lets see how many values my key variable contains. To do this we need to use a property called ValueCount.

接下来让我们看看我的键变量包含多少个值。 为此,我们需要使用一个名为ValueCount的属性。

$key.ValueCount

$ key.ValueCount

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

As you can see there are 6 values. It tells us how many values there are but doesn’t tell us what the values are called to do that you need to take a look at the keys property property.

如您所见,有6个值。 它告诉我们有多少个值,但没有告诉我们要看这些键属性需要调用什么值。

$key.Property

$ key.Property

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

If you want to retrieve the contents of the values you can use the PSPath property along with the Get-ItemProperty command as follows. We will create a variable called value to help us with receiving individual values.

如果要检索值的内容,则可以如下使用PSPath属性和Get-ItemProperty命令。 我们将创建一个名为value的变量,以帮助我们接收单个值。

$value = Get-ItemProperty $key.PSPath

$ value = Get-ItemProperty $ key.PSPath

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

That will retrieve the contents for all values in the key, but because we created the value variable we can parse it an individual property to retrieve. For example.

这将检索键中所有值的内容,但是由于我们创建了value变量,因此可以将其解析为单个属性以进行检索。 例如。

$value.Shellstate

$ value.Shellstate

Will return only the contents of the Shellstate value.

将仅返回Shellstate值的内容。

创建** (Creating  Keys)

Creating new keys is like creating a new folder:

创建新**就像创建一个新文件夹:

New-Item -type Directory “Type New Key Name Here”

新建项类型目录“在此处键入新键名”

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

删除金钥 (Deleting Keys)

Deleting a key is done using  the Remove-Item command like so:

删除**是使用Remove-Item命令完成的,如下所示:

Remove-Item “Type New Key Name Here”

删除项“在此处键入新**名称”

专家怪胎:使用PowerShell浏览注册表命令行样式,就像驱动器一样

创造价值 (Creating Values)

To add new values to a key you must use the Set-ItemProperty

要将新值添加到键,必须使用Set-ItemProperty

ItemType Holds DataType
String A string REG_SZ
ExpandedString A string with environment variables that are resolved when invoked REG_EXPANDED_SZ
Binary Binary value REG_BINARY
DWord Numeric Value REG_DWORD
MultiString Text of multiple lines REG_MULTI_SZ
QWord 64-Bit numeric values REG_QWORD
物品种类 持有 数据类型
一串 REG_SZ
ExpandedString 具有调用时可解析的环境变量的字符串 REG_EXPANDED_SZ
二元 二进制值 REG_BINARY
双字 数值 REG_DWORD
多字符串 多行文字 REG_MULTI_SZ
QWord 64位数值 REG_QWORD

To create a value use the following syntax:

要创建值,请使用以下语法:

Set-ItemProperty HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer –type string –name “New Value” –value “123”

Set-ItemProperty HKCU:\ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer –类型字符串–名称“ New Value” –值“ 123”

You can replace the path for the key in which you want to create the value and you can substitute the –type parameter for a different type from the above table.

您可以替换要在其中创建值的键的路径,也可以将–type参数替换为与上表不同的类型。

删除值 (Deleting Values)

You can delete values using the Remove-ItemProperty command.

您可以使用Remove-ItemProperty命令删除值。

Remove-ItemProperty HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer “New Value”

Remove-ItemProperty HKCU:\ Software \ Microsoft \ Windows \ CurrentVersion \ Explorer“新值”

翻译自: https://www.howtogeek.com/77677/expert-geek-navigate-the-registry-command-line-style-like-its-a-drive-using-powershell/