Image Factory for Microsoft Deployment Toolkit
PowerShell based WIM file generation factory of custom Windows builds.
For full instructions and documentation, visit my blog post
Please consider donating to support my work:
- You can support me on a monthly basis using Patreon.
- You can support me with a one-time payment using PayPal or by using Kofi.
My Image Factory script can also be downloaded from:
Tweet me if you have questions: @mikegalvin_
Features and Requirements
- The script is designed to run on a device with MDT installed.
- The device must also have Hyper-V management tools installed.
- The MDT shares can be local or on a remote device.
- The Hyper-V host can be local or on a remote device.
The script has been tested on Hyper-V installations on Windows 10, Windows Server 2016 (Datacenter and Core installations) and Windows Server 2012 R2 (Datacenter and Core Installations) and MDT installations on Windows 10 and Windows Server 2016 (GUI installs only).
Generating A Password File
The password used for SMTP server authentication must be in an encrypted text file. To generate the password file, run the following command in PowerShell, on the computer that is going to run the script and logged in with the user that will be running the script. When you run the command you will be prompted for a username and password. Enter the username and password you want to use to authenticate to your SMTP server.
Please note: This is only required if you need to authenticate to the SMTP server when send the log via e-mail.
$creds = Get-Credential $creds.Password | ConvertFrom-SecureString | Set-Content c:\scripts\ps-script-pwd.txt
After running the commands, you will have a text file containing the encrypted password. When configuring the -Pwd switch enter the path and file name of this file.
The local or UNC path to the build share of MDT. This and the deploy switch can point to the same location.
The local or UNC path to the deploy share of MDT. This and the build switch can point to the same location.
The comma-separated list of task sequence ID's to build.
The name of the computer running Hyper-V. Can be local or remote.
The path relative to the Hyper-V server of where to store the VHD file for the VM(s).
The path relative to the Hyper-V server of where the ISO file to boot from is stored.
The name of the virtual switch that the VM should use to communicate with the network.
Set if the Hyper-V server is WS2012 R2 and the script is running on Windows 10 or Windows Server 2016. This loads the older version of the Hyper-V module so it is able to manage WS2012 R2 Hyper-V VMs.
Set if the Hyper-V server is a remote device. Do not include this switch if the script is running on the same device as Hyper-V.
The path to output the log file to. The file name will be Image-Factory-YYYY-MM-dd-HH-mm-ss.log
The email subject that the email should have. Encapulate with single or double quotes.
The e-mail address the log should be sent to.
The e-mail address the log should be sent from.
The DNS name or IP address of the SMTP server.
The user account to connect to the SMTP server.
The txt file containing the encrypted password for the user account.
Configures the script to connect to the SMTP server using SSL.
Image-Factory.ps1 -Build \\mdt01\BuildShare$ -Deploy \\mdt01\DeploymentShare$ -VH hyperv01 -VHD C:\Hyper-V\VHD -Boot C:\iso\LiteTouchPE_x64.iso -VNic vSwitch-Ext -Remote -TS W10-1803,WS16-S -L C:\scripts\logs -Subject 'Server: Image Factory' -SendTo firstname.lastname@example.org -From email@example.com -Smtp smtp.outlook.com -User user -Pwd C:\foo\pwd.txt -UseSsl
This string will build two WIM from the two task sequences: W10-1803 & WS16-S. They will be imported to the deployment share on MDT01. The Hyper-V server used will be hyperv01, the VHD for the VMs generated will be stored in C:\Hyper-V\VHD on the server hyperv01. The boot iso file will be C:\iso\LiteTouchPE_x64.iso, located on the Hyper-V server. The Virtual Switch used by the VM will be called vSwitch-Ext. The log file will be output to C:\scripts\logs and it will be e-mailed with a custom subject line, using an SSL conection.