Powershell - 获取保存到变量的注册表值的数据

标签 powershell

我需要将注册表项中的单个数据项保存到变量中。我试过以下没有任何运气:

$dxVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\DirectX").GetValue("Version",$null)

我只想将版本号保存到变量中,别无其他。不是名字,只是数据。

在此先感谢您的帮助!

最佳答案

你几乎拥有它。尝试:

$dxVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\DirectX").Version

Get-ItemProperty返回一个带有许多属性的 PSCustomObject——其中的版本。我上面使用的这种点符号允许您快速访问任何属性的值。

或者,so long as you specify a scalar property ,您可以使用 Select-Object 的 ExpandProperty 参数:
$dxVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\DirectX") | Select-Object -ExpandProperty Version

关于Powershell - 获取保存到变量的注册表值的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18859158/

相关文章:

powershell - 如何将参数从 C# 传递到 PowerShell 脚本文件?

excel - 使用 Powershell 删除 Excel 中的前四行

windows - 我可以在 Emacs 的 shell 模式下使用 PowerShell 吗?

json - 无法使用Powershell提取json值

powershell - 跨域远程处理-确定使用哪些凭据的问题

unit-testing - Powershell 如何影响 TFS2015 中的测试执行

powershell - Pester:如何阻止我的脚本运行?

powershell - ffmpeg与Powershell的cmd等效

PowerShell 的 Invoke-RestMethod 相当于curl -u(基本身份验证)

powershell - 如何在PowerShell脚本中调用计算机名称,然后重命名最后5个字符?