Instantly share code, notes, and snippets.

Embed
What would you like to do?
<# This script contains all of the command shown in my blog post: Create Zero-Touch Windows 10 ISO
http://blogs.catapultsystems.com/mdowst/archive/2017/12/11/create-zero-touch-windows-10-iso/
#>
$ISO = "E:\Windows.iso"
$FolderPath = "E:\Win10_ISO\"
###################################
#
# Prep the ISO Files
#
###################################
# Get current drive letters
$drives = (Get-Volume).DriveLetter
# Mount the ISO image
$image = Mount-DiskImage -ImagePath $ISO -PassThru
# Get the new drive letter
$drive = (Get-Volume | ?{$drives -notcontains $_.DriveLetter -and $_.DriveLetter -ne $null}).DriveLetter
# Create destination folder if it doesn't exist
If (!(test-path $FolderPath)){
New-Item -type directory -Path $FolderPath}
# Copy the ISO files
Get-ChildItem -Path "$($drive):\" | %{
Copy-Item -Path $_.FullName -Destination $FolderPath -recurse -Force}
# dismount the ISO
$image | Dismount-DiskImage
# Delete the bootfix.bin
Remove-Item (Join-Path $FolderPath "boot\bootfix.bin") -Force
# Rename the efisys files
Rename-Item (Join-Path $FolderPath "efi\microsoft\boot\efisys.bin") "efisys_prompt.bin"
Rename-Item (Join-Path $FolderPath "efi\microsoft\boot\efisys_noprompt.bin") "efisys.bin"
# Rename install.esd to install.wim
If (Test-Path $(Join-Path $FolderPath "source\install.esd")){
Rename-Item $(Join-Path $FolderPath "source\install.esd") "install.wim"
}
###################################
#
# Create Autounattend.xml
#
###################################
[string]$password = Read-Host -Prompt "Enter the admin password to use"
[string]$ComputerName = Read-Host -Prompt "Enter the computer name use '*' to randomly generate it"
[string]$RegisteredOwner = Read-Host -Prompt "Enter the Registered Owner"
[string]$RegisteredOrganization = Read-Host -Prompt "Enter the Registered Organization"
$AutounattendXML = $(Join-Path $FolderPath "Autounattend.xml")
# Download the sample Autounattend.xml
$Uri = "https://gist.githubusercontent.com/mdowst/e81cc0608a0c554d8c3381ebc7b6e15e/raw/dc55c6c1eef66fc0c4db0652ce8300e9ff507e0f/Autounattend.xml"
Invoke-WebRequest -Uri $Uri -OutFile $AutounattendXML
# load the Autounattend.xml
[xml]$Autounattend = Get-Content $AutounattendXML
# Update the values
($Autounattend.unattend.settings | ?{$_.pass -eq 'oobeSystem'}).component.AutoLogon.Password.Value = $password
($Autounattend.unattend.settings | ?{$_.pass -eq 'oobeSystem'}).component.UserAccounts.AdministratorPassword.Value = $password
($Autounattend.unattend.settings | ?{$_.pass -eq 'specialize'}).component.ComputerName = $ComputerName
($Autounattend.unattend.settings | ?{$_.pass -eq 'specialize'}).component.RegisteredOwner = $RegisteredOwner
($Autounattend.unattend.settings | ?{$_.pass -eq 'specialize'}).component.RegisteredOrganization = $RegisteredOrganization
# Save the updated XML file
$Autounattend.Save($AutounattendXML)
###################################
#
# Create the ISO
#
###################################
# Create the ISO image
$DevToolsDirectory = "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\"
$NewISO = 'E:\Win10Entx64.iso'
$command = $(Join-Path $DevToolsDirectory 'amd64\Oscdimg\oscdimg.exe')
$arguments = '-m','-o','-u2','-udfver102',"-bootdata:2#p0,e,b$(Join-Path $FolderPath 'boot\etfsboot.com')#pEF,e,b$(Join-Path $FolderPath 'efi\microsoft\boot\efisys.bin')",$FolderPath,$NewISO
& $command $arguments
###################################
#
# Create Virtual Machine
#
###################################
# Create new VM and install OS
$VM = 'blog01'
$ISO = "E:\Win10Entx64.iso"
$Path = "E:\Virtual Machines"
$SwitchName = 'External NIC'
New-VM –Name $VM –NewVHDPath (Join-Path $Path "$VM\$VM.vhdx") -NewVHDSizeBytes 40GB -SwitchName $SwitchName -Path $Path -Generation 2
Set-VMMemory -VMName $VM -DynamicMemoryEnabled $true -MinimumBytes 512MB -MaximumBytes 2048MB -Buffer 20 -StartupBytes 1024MB
Add-VMDvdDrive -VMName $VM -Path $ISO
Set-VMFirmware -VMName $VM -BootOrder $(Get-VMDvdDrive -VMName $VM),$(Get-VMHardDiskDrive -VMName $VM)
Start-VM $VM
vmconnect localhost $VM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment