Public/Get-RegKeyWinCurVer.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<#
.SYNOPSIS
Returns the Registry Key values from HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion
 
.DESCRIPTION
Returns the Registry Key values from HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion for Online and Offline Windows Images
 
.LINK
https://osd.osdeploy.com/module/functions/get-regkeywincurver
 
.NOTES
19.11.20 Added Pipeline Support
19.11.9 David Segura @SeguraOSD Initial Release
#>

function Get-RegKeyWinCurVer {
    [CmdletBinding()]
    Param (
        #Specifies the full path to the root directory of the offline Windows image that you will service.
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]$Path,

        [ValidateSet(
            'BaseBuildRevisionNumber',
            'BuildBranch',
            'BuildGUID',
            'BuildLab',
            'BuildLabEx',
            'CompositionEditionID',
            'CurrentBuild',
            'CurrentBuildNumber',
            'CurrentMajorVersionNumber',
            'CurrentMinorVersionNumber',
            'CurrentType',
            'CurrentVersion',
            'EditionID',
            'InstallationType',
            'ProductId',
            'ProductName',
            'ReleaseId',
            'UBR'
            )]
        [string]$Property
    )
    Begin {}
    Process {
        $Global:GetRegKeyWinCurVer = $null

        if ($Path) {
            if (-not (Test-Path $Path -ErrorAction SilentlyContinue)) {Write-Warning "Unable to locate Mounted WindowsImage at $Path"; Break}
            Write-Verbose $Path
        
            $RegHive = "$Path\Windows\System32\Config\SOFTWARE"
            if (-not (Test-Path $RegHive)) {Write-Warning "Unable to locate RegHive at $RegHive"; Break}
        
            reg LOAD 'HKLM\OSD' "$Path\Windows\System32\Config\SOFTWARE" | Out-Null
            $Global:GetRegKeyWinCurVer = Get-ItemProperty -Path 'HKLM:\OSD\Microsoft\Windows NT\CurrentVersion'
            reg UNLOAD 'HKLM\OSD' | Out-Null
            Start-Sleep -Seconds 1
        } else {
            $Global:GetRegKeyWinCurVer = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
        }

        if ($Property) {
            Return ($Global:GetRegKeyWinCurVer).$Property
        } else {
            Return $Global:GetRegKeyWinCurVer
        }
    }
    End {}
}