Packer.Images/scripts/New-WindowsImageJob.ps1

51 lines
1.2 KiB
PowerShell
Raw Normal View History

#Requires -Modules 'dism'
Param(
[Parameter(Mandatory)]
[string]$ImageName,
[Parameter(Mandatory)]
[string]$SourceFolder,
[Parameter(Mandatory)]
[string]$DestinationFile
)
$StartJobSplat = @{
ArgumentList = $ImageName, $SourceFolder, $DestinationFile
ScriptBlock = {
Param(
$ImageName,
$SourceFolder,
$DestinationFile
)
$NewWindowsImageSplat = @{
Name = $ImageName
CapturePath = $SourceFolder
ImagePath = $DestinationFile
Verify = $True
}
New-WindowsImage @NewWindowsImageSplat
}
}
$Job = Start-Job @StartJobSplat
While ($Job.State -eq 'Running') {
$GetItemSplat = @{
Path = $DestinationFile
ErrorAction = 'SilentlyContinue'
}
$OutputFile = Get-Item @GetItemSplat
If ($OutputFile) {
Write-Host "Export in progress ... $($OutputFile.FullName); Size: $('{0:n2}' -f ($OutputFile.Length / 1MB))MB"
}
Else {
Write-Host "Export initiating ... "
}
$StartSleepSplat = @{
Seconds = 30
}
Start-Sleep @StartSleepSplat
}
Receive-Job $Job
Remove-Job $Job