Skip to content

Commit f75303f

Browse files
committed
Created for version 4.0.0.1
1 parent b70894c commit f75303f

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed

Src/Private/Import-Win32API.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Function Import-Win32API
2+
{
3+
[CmdletBinding(DefaultParameterSetName = 'Load')]
4+
Param
5+
(
6+
[Parameter(ParameterSetName = 'Load')]
7+
[Switch]$Load,
8+
[Parameter(ParameterSetName = 'Unload')]
9+
[Switch]$Unload
10+
)
11+
12+
$Win32APIParams = @{ Namespace = 'Win32API'; PassThru = $true }
13+
Switch ($PSCmdlet.ParameterSetName)
14+
{
15+
'Load'
16+
{
17+
$Win32APIParams.MemberDefinition = '[DllImport("advapi32.dll", SetLastError = true)] public static extern Int32 RegLoadKey(Int32 hKey, String lpSubKey, String lpFile);'
18+
$Win32APIParams.Name = 'Win32RegLoad'
19+
Break
20+
}
21+
'Unload'
22+
{
23+
$Win32APIParams.MemberDefinition = '[DllImport("advapi32.dll", SetLastError = true)] public static extern Int32 RegUnLoadKey(Int32 hKey, String lpSubKey);'
24+
$Win32APIParams.Name = 'Win32RegUnLoad'
25+
Break
26+
}
27+
}
28+
Add-Type @Win32APIParams
29+
}

Src/Public/Get-ErrorRecord.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Function Get-ErrorRecord
2+
{
3+
[CmdletBinding()]
4+
Param ()
5+
6+
$Index = 0
7+
($Error | ForEach-Object -Process {
8+
[PSCustomObject]@{
9+
Index = $Index
10+
Exception = $PSItem.Exception.Message
11+
Category = $PSItem.CategoryInfo.ToString()
12+
ErrorID = $PSItem.FullyQualifiedErrorId
13+
Target = $PSItem.TargetObject
14+
Command = $PSItem.InvocationInfo.Line.Trim()
15+
Script = $PSItem.InvocationInfo.ScriptName
16+
Line = $PSItem.InvocationInfo.ScriptLineNumber
17+
Column = $PSItem.InvocationInfo.OffsetInLine
18+
}
19+
$Index++
20+
} | Format-List | Out-String).Trim()
21+
}

Src/Public/Get-ImageData.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 / 1GB).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+
}

Src/Public/Get-Path.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Function Get-Path
2+
{
3+
[CmdletBinding(DefaultParameterSetName = 'None')]
4+
[OutputType([IO.FileSystemInfo])]
5+
Param
6+
(
7+
[Parameter(Mandatory = $true,
8+
ValueFromPipeline = $true,
9+
ValueFromPipelineByPropertyName = $true,
10+
Position = 0)]
11+
[Alias('FullName')]
12+
[String[]]$Path,
13+
[Parameter(ParameterSetName = 'Join',
14+
Position = 1)]
15+
[String]$ChildPath,
16+
[Parameter(ParameterSetName = 'Split',
17+
Position = 1)]
18+
[ValidateSet('Parent', 'Leaf')]
19+
[String]$Split = 'Parent'
20+
)
21+
22+
Begin
23+
{
24+
$DefaultErrorAction = $ErrorActionPreference
25+
$ErrorActionPreference = 'SilentlyContinue'
26+
}
27+
Process
28+
{
29+
ForEach ($Item In $Path)
30+
{
31+
If (Test-Path -LiteralPath $Item)
32+
{
33+
If ((Get-Item -LiteralPath $Item -Force) -is [Microsoft.Win32.RegistryKey]) { $IsRegistry = $true }
34+
Else { $Item = (Get-Item -LiteralPath $Item -Force).FullName }
35+
}
36+
If ($PSCmdlet.ParameterSetName -eq 'Join' -and $ChildPath)
37+
{
38+
If ($IsRegistry) { $PackagePath = Join-Path -Path $Item -ChildPath $ChildPath }
39+
Else { $PackagePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Join-Path -Path $Item -ChildPath $ChildPath)) }
40+
}
41+
ElseIf ($PSCmdlet.ParameterSetName -eq 'Split')
42+
{
43+
Switch ($PSBoundParameters.Split)
44+
{
45+
'Parent'
46+
{
47+
If ($IsRegistry) { $PackagePath = Split-Path -Path $Item -Parent }
48+
Else { $PackagePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath((Split-Path -Path $Item -Parent)) }
49+
}
50+
'Leaf'
51+
{
52+
$PackagePath = Split-Path -Path $Item -Leaf
53+
}
54+
}
55+
}
56+
Else
57+
{
58+
If ($IsRegistry) { $PackagePath = $Item }
59+
Else { $PackagePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Item) }
60+
}
61+
If ((Test-Path -Path $PackagePath) -and !$IsRegistry) { (Get-Item -LiteralPath $PackagePath -Force).FullName }
62+
Else { $PackagePath }
63+
}
64+
}
65+
End
66+
{
67+
$ErrorActionPreference = $DefaultErrorAction
68+
}
69+
}

0 commit comments

Comments
 (0)