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

sshot-11

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。

sshot-7

When PowerShell opens, type:

打开PowerShell后,键入:

cd HKCU:

CD HKCU:

To change to the HKEY_CURRENT _USER hive.

更改为HKEY_CURRENT _USER配置单元。

sshot-9

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

迪尔

sshot-1

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

sshot-3

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

sshot-4

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

sshot-5

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

sshot-7

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”

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

sshot-8

删除金钥 (Deleting Keys)

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

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

Remove-Item “Type New Key Name Here”

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

sshot-10

创造价值 (Creating Values)

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

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

ItemTypeHoldsDataType
StringA stringREG_SZ
ExpandedStringA string with environment variables that are resolved when invokedREG_EXPANDED_SZ
BinaryBinary valueREG_BINARY
DWordNumeric ValueREG_DWORD
MultiStringText of multiple linesREG_MULTI_SZ
QWord64-Bit numeric valuesREG_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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值