Automate Creation of WIM Files
Image Factory Utility can also be downloaded from:
A demonstration video is available on my YouTube channel.
Please consider supporting my work:
Features and Requirements
- This utility is designed to run on a computer with Microsoft Deployment Toolkit installed.
- The computer must have the Hyper-V management PowerShell modules installed.
- The primary function of this utility is to automate the production of WIM files from MDT task sequences.
- The utility requires at least PowerShell 5.0.
- This utility has been tested on Windows 10, Windows Server 2019, Windows Server 2016 and Windows Server 2012 R2.
The utility will make changes to your customsettings.ini file, although it will make a backup first. These changes are necessary so that the build process runs automated. Depending on your environment, you may need to make additional changes to your customsettings.ini.
Separating your build and deployment shares
I would recommend running with a separate build share so that:
- The image factory utility doesn’t tie up the main deployment share whilst running.
- The build environment can be configured separately.
- The boot media for the build share can be configured to automatically log into the deployment environment.
Here are the settings you’ll need to add to your Bootstrap.ini to automatically log into the build share. Don’t forget to update your build share in MDT and regenerate the boot images.
[Settings] Priority=Default [Default] DeployRoot=\\mdt01\BuildShare$ UserDomain=corp.contoso.com UserID=mdt_admin UserPassword=P@ssw0rd SkipBDDWelcome=YES
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 and logged in with the user that will be running the utility. 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 table below shows all the command line options available with descriptions and example configurations.
|Command Line Switch||Description||Example|
|-Build||Location of the build share. It can be the same as the deployment share, and it can be a local or UNC path.||\\server\buildshare$ OR C:\BuildShare|
|-Deploy||Location of the deployment share. It can be the same as the deployment share, and it can be a local or UNC path.||\\server\deploymentshare$ OR C:\DeploymentShare|
|-Vh||Name of the Hyper-V host. Can be a local or remote device.||VS01|
|-Vhd||The path relative to the Hyper-V server of where to put the VHD file for the VM(s) that will be generated.||C:\Hyper-V\VHD|
|-Boot||The path relative to the Hyper-V server of where the ISO file is to boot from.||C:\iso\LiteTouchPE_x64.iso|
|-Vnic||Name of the virtual switch that the virtual machine should use to communicate with the network. If the name of the switch contains a space encapsulate with single or double quotes.||vSwitch-Ext|
The comma-separated list of task sequence ID’s to build.
Use this switch if the Hyper-V server is Windows Server 2012 R2 and the script is running on Windows 10 or Windows Server 2016/2019. This loads the older version of the Hyper-V module, so it can manage WS2012 R2 Hyper-V VMs.
Use this switch if the Hyper-V server is a remote device. Do not use this switch if the script is running on the same device as Hyper-V.
|-NoBanner||Use this option to hide the ASCII art title in the console.||N/A|
|-L||The path to output the log file to. The file name will be Image-Factory_YYYY-MM-dd_HH-mm-ss.log. Do not add a trailing \ backslash.||C:\foo|
|-Subject||The subject line for the e-mail log. Encapsulate with single or double quotes. If no subject is specified, the default of ”
Image Factory Utility Log
” will be used.
|-SendTo||The e-mail address the log should be sent email@example.com|
|-From||The e-mail address the log should be sent from.||
|-Smtp||The DNS name or IP address of the SMTP server.||smtp.live.com OR smtp.office365.com|
|-User||The user account to authenticate to the SMTP firstname.lastname@example.org|
|-Pwd||The txt file containing the encrypted password for SMTP authentication.||C:\scripts\ps-script-pwd.txt|
|-UseSsl||Configures the utility to connect to the SMTP server using SSL.||N/A|
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-1909,WS19-DC -L C:\scripts\logs -Subject 'Server: Image Factory' -SendTo email@example.com -From firstname.lastname@example.org -Smtp smtp.outlook.com -User user -Pwd C:\foo\pwd.txt -UseSsl
The above command will build WIM files from the task sequences W10-1909 and WS19-DC. They will be imported to the deployment share on MDT01. The Hyper-V host used will be HYPERV01 and the VHDs for the VMs generated will be stored in C:\Hyper-V\VHD on the host. The boot ISO file will be C:\iso\LiteTouchPE_x64.iso, also located on the Hyper-V host. The virtual switch used by the VMs will be called vSwitch-Ext. The log file will be output to C:\scripts\logs and e-mailed with a custom subject line.
2020-02-27: Version 2020.02.24 ‘Robot’
- Refactored code.
- Fully backwards compatible.
- Added ASCII banner art when run in the console.
- Added option to disable the ASCII banner art.
- Added custom subject line for e-mail.
- The script will now set automatic checkpoints to ‘disabled’ on the VM’s. This is to help with VM disk management and clean up.
- Changed SMTP authentication to require an encrypted password file.
- Added instructions on how to generate an encrypted password file.
- Added necessary information to add the script to the PowerShell Gallery.
- Added a sanity check of the MDT deployment share. The script now checks for an existing CustomSettings-backup.ini file. If it exists, it reports that the deployment share is not clean.
- Added extra line breaks when editing the CustomSettings.ini as previously it was adding the required configuration on the last line of the ini file and causing the deployment to fail. Many thanks to Twitter user @thestardawg for reporting this bug.
- Improved logging so that the log file and console output is now more readable.
- Improved commenting on the code for documentation purposes.
- Added authentication and SSL options for e-mail notification.
- Added command line configuration options so the script itself does not need to be edited.
- Added code to manage the Virtual Machines without the need for extra configuration options.
- Removed some unnecessary extra configuration options and variables.
I’ve added logging to the script and the ability to email the log on completion. I’ve also added a variable to configure the Virtual Switch that the VM’s Network Adaptor should use. This was an oversight on the previous version.
2017-04-17 Minor update
I’ve added hour and minutes to the WIM file creation name as I have been running multiple images of the same Task Sequence within a day and needed some extra data to prevent the image from over writing the previous one. I’ve also made another script, using this one as a base so I can generate VMs to test the deployment of the captured images after I’ve manually renamed them in MDT and added to the task sequences. The VMs are named after the Task Sequence ID and do not delete after the Task Sequence completes.