Reputation: 146
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!
Upvotes: 8
Views: 31862
Reputation: 26013
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
Upvotes: 15