How do I get the value of a registry key and ONLY the value using powershell

前端 未结 9 568
醉酒成梦
醉酒成梦 2020-12-13 11:52

Can anyone help me pull the value of a registry key and place it into a variable in PowerShell? So far I have used Get-ItemProperty and reg query

9条回答
  •  半阙折子戏
    2020-12-13 12:41

    $key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
    (Get-ItemProperty -Path $key -Name ProgramFilesDir).ProgramFilesDir
    

    I've never liked how this was provider was implemented like this : /

    Basically, it makes every registry value a PSCustomObject object with PsPath, PsParentPath, PsChildname, PSDrive and PSProvider properties and then a property for its actual value. So even though you asked for the item by name, to get its value you have to use the name once more.

提交回复
热议问题