Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - Get Data of Registry Value Saved to a Variable

Tags:

powershell

I need to save a single data item in a registry key to a variable. I've tried the following without any luck:

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

I want JUST the version number saved to the variable, nothing else. Not the name, just the data.

Thanks in advance for your help!

like image 653
Lawivido Avatar asked Sep 17 '13 20:09

Lawivido


1 Answers

You almost had it. Try:

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

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

Alternatively, so long as you specify a scalar property, you could use the ExpandProperty parameter of Select-Object:

$dxVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\DirectX") | Select-Object -ExpandProperty Version
like image 121
Anthony Neace Avatar answered Sep 19 '22 12:09

Anthony Neace