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

前端 未结 9 579
醉酒成梦
醉酒成梦 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:33

    I'm not sure if this has been changed, or if it has something to do with which version of PS you're using, but using Andy's example, I can remove the -Name parameter and I still get the value of the reg item:

    PS C:\> $key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion'
    PS C:\> (Get-ItemProperty -Path $key).ProgramFilesDir
    C:\Program Files
    
    
    PS C:\> $psversiontable.psversion
    
    Major  Minor  Build  Revision
    -----  -----  -----  --------
    2      0      -1     -1
    

提交回复
热议问题