Powershell - Get registry data stored in a variable

I need to save one data item in the registry key of a variable. I tried the following with no luck:

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

I want the version number to be stored in a variable, and nothing more. Not a name, just data.

Thanks in advance for your help!

+4
source share
1 answer

You almost had it. Try:

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

Get-ItemProperty returns a PSCustomObject with a number of properties - The version among them. This kind of dotted notation, as I used above, allows you to quickly access the value of any property.

Alternatively, while you specify a scalar property , you can use the ExpandProperty Select-Object parameter:

 $dxVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\DirectX") | Select-Object -ExpandProperty Version 
+8
source

Source: https://habr.com/ru/post/1502678/


All Articles