1
+ Function Get-ImageData
2
+ {
3
+ [CmdletBinding (DefaultParameterSetName = ' ImageData' )]
4
+ [OutputType ([PSCustomObject ])]
5
+ Param
6
+ (
7
+ [Parameter (ParameterSetName = ' ImageData' ,
8
+ Mandatory = $true ,
9
+ ValueFromPipeline = $true ,
10
+ Position = 0 )]
11
+ [IO.FileInfo ]$ImageFile ,
12
+ [Parameter (ParameterSetName = ' ImageData' ,
13
+ Mandatory = $false ,
14
+ Position = 1 )]
15
+ [Int ]$Index = 1 ,
16
+ [Parameter (ParameterSetName = ' Update' )]
17
+ [Switch ]$Update
18
+ )
19
+
20
+ Process
21
+ {
22
+ If ($PSCmdlet.ParameterSetName -eq ' ImageData' )
23
+ {
24
+ $ArchString = @ { [UInt32 ]0 = ' x86' ; [UInt32 ]5 = ' arm' ; [UInt32 ]6 = ' ia64' ; [UInt32 ]9 = ' amd64' ; [UInt32 ]12 = ' arm64' }
25
+ $ImageDataFile = $ImageFile.BaseName.Replace ($ImageFile.BaseName [0 ], $ImageFile.BaseName [0 ].ToString().ToUpper()).Insert($ImageFile.BaseName.Length , ' Info.xml' )
26
+ $ImageInfo = (Get-WindowsImage - ImagePath $ImageFile.FullName - Index $Index - ErrorAction:$ErrorActionPreference )
27
+ $ImageData = [PSCustomObject ][Ordered ]@ {
28
+ Path = $ImageInfo.ImagePath
29
+ Index = $ImageInfo.ImageIndex
30
+ Name = $ImageInfo.ImageName
31
+ Description = $ImageInfo.ImageDescription
32
+ Size = [Math ]::Round($ImageInfo.ImageSize / 1 GB ).ToString() + " GB"
33
+ Edition = $ImageInfo.EditionID
34
+ Version = $ImageInfo.Version
35
+ Build = $ImageInfo.Build
36
+ Release = $null
37
+ CodeName = $null
38
+ Architecture = $ArchString [$ImageInfo.Architecture ]
39
+ Language = $ImageInfo.Languages [$ImageInfo.DefaultLanguageIndex ]
40
+ InstallationType = $ImageInfo.InstallationType
41
+ Created = $ImageInfo.CreatedTime
42
+ }
43
+ If ($ImageFile.Name -ne ' install.wim' ) { @ (' Release' , ' CodeName' , ' Created' ) | ForEach-Object - Process { $ImageData.PSObject.Properties.Remove ($PSItem ) } }
44
+ $ImageData | Export-Clixml - Path (Get-Path - Path $WorkFolder - ChildPath $ImageDataFile ) - ErrorAction:$ErrorActionPreference
45
+ }
46
+ ElseIf ($PSCmdlet.ParameterSetName -eq ' Update' )
47
+ {
48
+ If (! (Get-ChildItem - Path $WorkFolder - Include InstallInfo.xml, CurrentVersion.xml - Recurse - File)) { Return }
49
+ $ImageData = Import-Clixml - Path (Get-Path - Path $WorkFolder - ChildPath InstallInfo.xml) - ErrorAction:$ErrorActionPreference
50
+ $CurrentVersion = Import-Clixml - Path (Get-Path - Path $WorkFolder - ChildPath CurrentVersion.xml) - ErrorAction:$ErrorActionPreference
51
+ If ($ImageData.Build -eq ' 18362' -and $CurrentVersion.CurrentBuildNumber -eq ' 18363' )
52
+ {
53
+ $ImageData.Version = $ImageData.Version.Replace ($ImageData.Build , $CurrentVersion.CurrentBuildNumber )
54
+ $ImageData.Build = $CurrentVersion.CurrentBuildNumber
55
+ }
56
+ $ImageData.Release = $CurrentVersion.ReleaseID
57
+ If ($CurrentVersion.CurrentBuildNumber -eq ' 18363' -and $CurrentVersion.BuildBranch.ToUpper ().Split(' _' )[0 ] -eq ' 19H1' ) { $ImageData.CodeName = ' 19H2' }
58
+ Else { $ImageData.CodeName = $CurrentVersion.BuildBranch.ToUpper ().Split(' _' )[0 ] }
59
+ @ (' Path' , ' Index' ) | ForEach-Object - Process { $ImageData.PSObject.Properties.Remove ($PSItem ) }
60
+ $ImageData.PSObject.TypeNames.Insert (0 , ' System.IO.Optimized.Wim' )
61
+ $ImageData | Add-Member - MemberType NoteProperty - Name Optimized - Value (Get-Date - Format ' G' )
62
+ $ImageData | Export-Clixml - Path (Get-Path - Path $WorkFolder - ChildPath InstallInfo.xml) - Force - ErrorAction:$ErrorActionPreference
63
+ }
64
+ $ImageData
65
+ }
66
+ }
0 commit comments