Question:
I need to save a single data item in a registry key to a variable. I’ve tried the following without any luck:
1 2 |
$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!
Answer:
You almost had it. Try:
1 2 |
$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
:
1 2 |
$dxVersion = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\DirectX") | Select-Object -ExpandProperty Version |