|
71 | 71 |
|
72 | 72 | [CmdletBinding()] |
73 | 73 | param ( |
74 | | - [Parameter(Mandatory = $true)] |
| 74 | + [Parameter(Mandatory = $false)] |
75 | 75 | [ValidateScript({if (!(Test-Path -Path $PSItem)) { return $false } else { return $true } })] |
76 | 76 | [string] $ImagePath, |
77 | 77 |
|
|
82 | 82 | [string] $MountPath, |
83 | 83 |
|
84 | 84 | [Parameter(Mandatory = $true)] |
85 | | - [string[]] $Artifact, |
| 85 | + [string] $Artifact, |
86 | 86 |
|
87 | 87 | [Parameter(Mandatory = $false)] |
88 | 88 | [string[]] $ArtifactParam, |
89 | 89 |
|
90 | 90 | [Parameter(Mandatory = $false)] |
91 | | - [Switch] $Force |
| 91 | + [Switch] $Force, |
92 | 92 |
|
| 93 | + [Parameter(Mandatory = $false)] |
| 94 | + [Switch] $Local |
93 | 95 | ) |
94 | 96 |
|
| 97 | + # TODO - validat eLOcal & ImagePath |
| 98 | + |
95 | 99 | ### If the user doesn't specify an output path, then generate one |
96 | 100 | if (!$PSBoundParameters.Keys.Contains('OutputPath')) { |
97 | 101 | $OutputPath = GenerateOutputFolder |
98 | 102 | } |
99 | | - elseif(($PSBoundParameters.Keys.Contains('OutputPath')) -and ($PSBoundParameters.Keys.Contains('Force'))) |
100 | | - { |
| 103 | + elseif(($PSBoundParameters.Keys.Contains('OutputPath')) -and ($PSBoundParameters.Keys.Contains('Force'))) { |
101 | 104 | $OutputPath = GenerateOutputFolder -Path $OutputPath -Force |
102 | 105 | } |
103 | 106 | else { |
104 | 107 | $OutputPath = GenerateOutputFolder -Path $OutputPath |
105 | 108 | } |
106 | | - Write-Verbose -Message ('Starting conversion process') |
107 | | - |
108 | | - ### Verify the image type before proceeding |
109 | | - $ImageType = GetImageType -Path $ImagePath |
110 | | - Write-Verbose -Message ('Image type is: {0}' -f $ImageType) |
111 | 109 |
|
112 | | - try { |
113 | | - ### Mount the image to a directory |
| 110 | + # load the source - local drive, or VHD |
| 111 | + if ($Local) { |
| 112 | + $MountPath = $env:SystemDrive |
| 113 | + $version = [Environment]::OSVersion.Version |
| 114 | + $ImageWindowsVersion = "$($version.Major).$($version.Minor)" |
| 115 | + Write-Verbose -Message "Using local drive: $MountPath" |
| 116 | + } |
| 117 | + else { |
| 118 | + # Verify the image type before proceeding |
| 119 | + $ImageType = GetImageType -Path $ImagePath |
| 120 | + Write-Verbose -Message ('Image type is: {0}' -f $ImageType) |
114 | 121 |
|
| 122 | + try { |
| 123 | + # Mount the image to a directory |
115 | 124 | $Mount = MountImage -ImagePath $ImagePath -MountPath $MountPath |
116 | | - Write-Verbose -Message ('Finished mounting image to: {0}' -f $Mount.Path) |
| 125 | + $MountPath = $Mount.Path |
| 126 | + Write-Verbose -Message ('Finished mounting image to: {0}' -f $MountPath) |
117 | 127 | } |
118 | 128 | catch { |
119 | 129 | throw 'Fatal error: couldn''t mount image file: {0}' -f $PSItem |
120 | 130 | } |
121 | 131 |
|
122 | | - ### Get the Windows version in the image, returns Major.Minor - e.g. 6.2 is Server 2012 |
123 | | - ### https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions |
124 | | - $info = Get-WindowsImage -Index 1 -ImagePath $ImagePath |
125 | | - $ImageWindowsVersion = "$($info.MajorVersion).$($info.MinorVersion)" |
126 | | - |
127 | | - ### Perform artifact discovery |
128 | | - if (!$PSBoundParameters.Keys.Contains('Artifact')) { |
129 | | - $Artifact = Get-WindowsArtifact |
130 | | - } |
131 | | - if (!$PSBoundParameters.Keys.Contains('ArtifactParam')) { |
132 | | - DiscoverArtifacts -Artifact $Artifact -OutputPath $OutputPath -ImageWindowsVersion $ImageWindowsVersion |
133 | | - } |
134 | | - else { |
135 | | - DiscoverArtifacts -Artifact $Artifact -OutputPath $OutputPath -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam |
| 132 | + # Get the Windows version in the image, returns Major.Minor - e.g. 6.2 is Server 2012 |
| 133 | + # https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions |
| 134 | + $info = Get-WindowsImage -Index 1 -ImagePath $ImagePath |
| 135 | + $ImageWindowsVersion = "$($info.MajorVersion).$($info.MinorVersion)" |
136 | 136 | } |
137 | 137 |
|
138 | | - ### Generate Dockerfile |
139 | | - if (!$PSBoundParameters.Keys.Contains('ArtifactParam')) { |
140 | | - GenerateDockerfile -ArtifactPath $OutputPath -Artifact $Artifact |
| 138 | + Write-Verbose -Message ('Starting conversion process') |
| 139 | + try { |
| 140 | + ### Perform artifact discovery |
| 141 | + if (!$PSBoundParameters.Keys.Contains('Artifact')) { |
| 142 | + $Artifact = Get-WindowsArtifact |
| 143 | + } |
| 144 | + if (!$PSBoundParameters.Keys.Contains('ArtifactParam')) { |
| 145 | + DiscoverArtifacts -MountPath $MountPath -Artifact $Artifact -OutputPath $OutputPath -ImageWindowsVersion $ImageWindowsVersion |
| 146 | + } |
| 147 | + else { |
| 148 | + DiscoverArtifacts -MountPath $MountPath -Artifact $Artifact -OutputPath $OutputPath -ImageWindowsVersion $ImageWindowsVersion -ArtifactParam $ArtifactParam |
| 149 | + } |
| 150 | + |
| 151 | + ### Generate Dockerfile |
| 152 | + if (!$PSBoundParameters.Keys.Contains('ArtifactParam')) { |
| 153 | + GenerateDockerfile -MountPath $MountPath -ArtifactPath $OutputPath -Artifact $Artifact |
| 154 | + } |
| 155 | + else { |
| 156 | + GenerateDockerfile -MountPath $MountPath -ArtifactPath $OutputPath -Artifact $Artifact -ArtifactParam $ArtifactParam |
| 157 | + } |
| 158 | + Write-Verbose -Message 'Finished generating the Dockerfile' |
141 | 159 | } |
142 | | - else { |
143 | | - GenerateDockerfile -ArtifactPath $OutputPath -Artifact $Artifact -ArtifactParam $ArtifactParam |
| 160 | + finally { |
| 161 | + if ($Mount) { |
| 162 | + ### Dismount the image when inspection is completed |
| 163 | + $null = Dismount-WindowsImage -Path $MountPath -Discard |
| 164 | + Write-Verbose -Message ('Finished dismounting the Windows image from {0}' -f $MountPath) |
| 165 | + } |
144 | 166 | } |
145 | | - Write-Verbose -Message 'Finished generating the Dockerfile' |
146 | | - |
147 | | - ### Dismount the image when inspection is completed |
148 | | - $null = Dismount-WindowsImage -Path $Mount.Path -Discard |
149 | | - Write-Verbose -Message ('Finished dismounting the Windows image from {0}' -f $Mount.Path) |
150 | | - |
151 | 167 | } |
152 | 168 |
|
0 commit comments