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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With