如何获取注册表项的值,并且仅使用Powershell获得值 [英] How do I get the value of a registry key and ONLY the value using powershell
问题描述
有人可以帮助我提取注册表项的值并将其放入PowerShell中的变量中吗?到目前为止,我已经使用了Get-ItemProperty
和reg query
,尽管两者都会提取值,但都还会添加额外的文本.我只需要注册表项中的字符串文本,而只需要注册表项中的字符串文本.我确定我可以创建一个函数来删除多余的文本,但是如果某些更改(即reg键名)可能会对此产生影响.
Can anyone help me pull the value of a registry key and place it into a variable in PowerShell? So far I have used Get-ItemProperty
and reg query
and although both will pull the value, both also add extra text. I need just the string text from the registry key and ONLY the string text from the key. I'm sure I could create a function to strip off the extra text but if something changes (i.e. reg key name) it might affect this.
推荐答案
$key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
(Get-ItemProperty -Path $key -Name ProgramFilesDir).ProgramFilesDir
我从未喜欢过这样的提供者是如何实现的:/
I've never liked how this was provider was implemented like this : /
基本上,它使每个注册表值都是具有PsPath
,PsParentPath
,PsChildname
,PSDrive
和PSProvider
属性的PSCustomObject
对象,然后是其实际值的属性.因此,即使您按名称要求输入商品,也要再次使用该名称才能获得其价值.
Basically, it makes every registry value a PSCustomObject
object with PsPath
, PsParentPath
, PsChildname
, PSDrive
and PSProvider
properties and then a property for its actual value. So even though you asked for the item by name, to get its value you have to use the name once more.
这篇关于如何获取注册表项的值,并且仅使用Powershell获得值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!