PowerTip: Use PowerShell to Read Registry Key Property Value

Doctor Scripto

Dr Scripto

Summary: Use Windows PowerShell to read a registry key property value.

Hey, Scripting Guy! Question How can I use Windows PowerShell to read a registry key property value so I can find the version of a particular software package?

Hey, Scripting Guy! Answer Use the Get-ItemProperty cmdlet, for example:

Get-ItemProperty -Path HKCU:\Software\ScriptingGuys\Scripts -Name version

Doctor Scripto
Dr Scripto

Scripter, PowerShell, vbScript, BAT, CMD

Follow Dr Scripto   

0 comments

  • Avatar
    Chris Quinn

    This may resturn better results depending on the property
    Get-ItemPropertyProperty -Path HKCU:\Software\ScriptingGuys\Scripts -Name version
    As an example I was looking for a correct Windows Build number which at first should be 
    [System.Environment]::OSVersion.Version
    The issue I had was with Windows returning a 0 for revision on  the Revision property when I knew I had installed service packs that should have updated the build. 
    In my case I found that the Registry Key “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\” Ccontained much more information including a UBR value, which appears to be the revision number for the build. To Duplicate the output of the [System.Environment]::OSVersion.Version I came up with teh following:
    $WindowsVersion = New-Object -TypeName PSObject
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Major -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name CurrentMajorVersionNumber)
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Minor -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name CurrentMinorVersionNumber)
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Build -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name CurrentBuild)
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Revision -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name UBR)
     
    $WindowsVersion
    Which returns the correct results

  • Avatar
    Chris Quinn

    This may resturn better results depending on the property
    Get-ItemPropertyProperty -Path HKCU:\Software\ScriptingGuys\Scripts -Name version
    As an example I was looking for a correct Windows Build number which at first should be 
    [System.Environment]::OSVersion.Version
    The issue I had was with Windows returning a 0 for revision on  the Revision property when I knew I had installed service packs that should have updated the build. 
    In my case I found that the Registry Key “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\” Ccontained much more information including a UBR value, which appears to be the revision number for the build. To Duplicate the output of the [System.Environment]::OSVersion.Version I came up with the following:
     
    $WindowsVersion = New-Object -TypeName PSObject
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Major -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name CurrentMajorVersionNumber)
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Minor -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name CurrentMinorVersionNumber)
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Build -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name CurrentBuild)
    $WindowsVersion | Add-Member -MemberType NoteProperty -Name Revision -Value $(Get-ItemPropertyValue -Path ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’ -Name UBR)
    $WindowsVersion
     
    Which returns the correct results

Leave a comment