How to Create Windows autounattend WinPE ISO on Windows Worker

This documentation is generated by Attune

Automate This

Use the Attune GUI for your Scripts

    1 Download Attune
    2 Copy the Attune Project URL
    3 Clone the Project in Attune
    4 Plan your Job(s)
    5 Run your Job(s)

You've automated: Create Windows autounattend WinPE ISO on Windows Worker


Get the most out of automation with our get started videos, product demonstrations, and more.

Learn Attune Automation

The following steps will guide you through the manual process.

Check if boot type is configured correctly.

Connect via RDP:

mstsc /admin /v:{automationworkerwindowsnode}

Login as user {automationworkerwindowsuseradministrator} and open a command prompt.

Execute the following script:

                
$values = "
    isBiosBoot = {isBiosBoot}
    isUefiBoot = {isUefiBoot}
    "

function printVals {
    Write-Host "${values}"
}

Write-Host "Checking ..."
printVals

[regex]$regex = 'true'

$COUNT = $regex.matches("${values}").count

Write-Host "COUNT=${COUNT}"

if ( $COUNT -ne 1 ) {
    Write-Host "FAIL: You must have exactly one only have one of the parameters above set to true"
    exit 1
}

Write-Host "SUCCESS: The parameters above are set correctly"
                
            

Check if Windows type is configured correctly.

Execute the following script:

                
$values = "
    isWindowsServer = {isWindowsServer}
    isWindowsWorkstation = {isWindowsWorkstation}
    "

function printVals {
    Write-Host "${values}"
}

Write-Host "Checking ..."
printVals

[regex]$regex = 'true'

$COUNT = $regex.matches("${values}").count

Write-Host "COUNT=${COUNT}"

if ( $COUNT -ne 1 ) {
    Write-Host "FAIL: You must have exactly one only have one of the parameters above set to true"
    exit 1
}

Write-Host "SUCCESS: The parameters above are set correctly"
                
            

To Debug
  • Uncomment out the Write-Hosts to debug.
Logic
  • For loop loops through each octet in the gateway IP address, subnet range octet and subnet mask.
  • For each octet:
    • The min octet is the subnet octet bitwised ANDed with the netmask octet.
    • A wildcard octet is 255 - netmask octet.
    • The max octet is the subnet octet bitwised ORed with the wildcard octet.
    • The gateway IP address octet is tested to see if it is between the min and max octets.
References

Subnet Cheat Sheet - 24 Subnet Mask, 30, 26, 27, 29, and other IP Address CIDR Network References

Execute the following script:

                
Write-Host "gateway IP address={newOsNodeSubnet.gateway}"
Write-Host "subnet={newOsNodeSubnet.subnet}"
Write-Host "netmask={newOsNodeSubnet.netmask}"
#Write-Host "i, GATEWAY_OCTET, SUBNET_OCTET, NETMASK_OCTET, WILDCARD_MASK, OCTET_MIN, OCTET_MAX"

$GATEWAY_OCTETS = "{newOsNodeSubnet.gateway}".split('.')
$SUBNET_OCTETS = "{newOsNodeSubnet.subnet}".split('.')
$NETMASK_OCTETS = "{newOsNodeSubnet.netmask}".split('.')

for ($i = 0; $i -lt 4; $i++) {
    $GATEWAY_OCTET = $GATEWAY_OCTETS[$i]
    $SUBNET_OCTET = $SUBNET_OCTETS[$i]
    $NETMASK_OCTET = $NETMASK_OCTETS[$i]
    
    $OCTET_MIN = $SUBNET_OCTET -band $NETMASK_OCTET

    $WILDCARD_MASK = 255 - $NETMASK_OCTET
    $OCTET_MAX = $SUBNET_OCTET -bor $WILDCARD_MASK
    
    #Write-Host "$i. $GATEWAY_OCTET, $SUBNET_OCTET, $NETMASK_OCTET, $WILDCARD_MASK, $OCTET_MIN, $OCTET_MAX"
    
    if ( ($GATEWAY_OCTET -ge $OCTET_MIN) -and
        ($GATEWAY_OCTET -le $OCTET_MAX) ) {
        Write-Host "Octet number $i, $OCTET_MIN <= $GATEWAY_OCTET <= $OCTET_MAX, ok."
    } else {
        Write-Host "Octet number $i, $OCTET_MIN <= $GATEWAY_OCTET <= $OCTET_MAX is false. Not in range of the subnet mask."
        exit 1
    }
}
                
            

To Debug
  • Uncomment out the Write-Hosts to debug.
Logic
  • For loop loops through each octet in the IP address, subnet range octet and subnet mask.
  • For each octet:
    • The min octet is the subnet octet bitwised ANDed with the netmask octet.
    • A wildcard octet is 255 - netmask octet.
    • The max octet is the subnet octet bitwised ORed with the wildcard octet.
    • The IP address octet is tested to see if it is between the min and max octets.
References

Subnet Cheat Sheet - 24 Subnet Mask, 30, 26, 27, 29, and other IP Address CIDR Network References

Execute the following script:

                
Write-Host "IP address={newOsNode.ip}"
Write-Host "subnet={newOsNodeSubnet.subnet}"
Write-Host "netmask={newOsNodeSubnet.netmask}"
#Write-Host "i, IP_OCTET, SUBNET_OCTET, NETMASK_OCTET, WILDCARD_MASK, OCTET_MIN, OCTET_MAX"

$IP_OCTETS = "{newOsNode.ip}".split('.')
$SUBNET_OCTETS = "{newOsNodeSubnet.subnet}".split('.')
$NETMASK_OCTETS = "{newOsNodeSubnet.netmask}".split('.')

for ($i = 0; $i -lt 4; $i++) {
    $IP_OCTET = $IP_OCTETS[$i]
    $SUBNET_OCTET = $SUBNET_OCTETS[$i]
    $NETMASK_OCTET = $NETMASK_OCTETS[$i]
    
    $OCTET_MIN = $SUBNET_OCTET -band $NETMASK_OCTET

    $WILDCARD_MASK = 255 - $NETMASK_OCTET
    $OCTET_MAX = $SUBNET_OCTET -bor $WILDCARD_MASK
    
    #Write-Host "$i. $IP_OCTET, $SUBNET_OCTET, $NETMASK_OCTET, $WILDCARD_MASK, $OCTET_MIN, $OCTET_MAX"
    
    if ( ($IP_OCTET -ge $OCTET_MIN) -and
        ($IP_OCTET -le $OCTET_MAX) ) {
        Write-Host "Octet number $i, $OCTET_MIN <= $IP_OCTET <= $OCTET_MAX, ok."
    } else {
        Write-Host "Octet number $i, $OCTET_MIN <= $IP_OCTET <= $OCTET_MAX is false. Not in range of the subnet mask."
        exit 1
    }
}
                
            

If kickstartedBootLoaderIsUefi is set true, then checks if at least one of these are also true: 1. isWin10Uefi 2. isWinServerUefi

Execute the following script:

                
if ( ${{kickstartedBootLoaderIsUefi}} ) {

    Write-Host "isUefiBoot = {isUefiBoot}"

    if ( -Not ${{isUefiBoot}} ) {

        Write-Host "If kickstartedBootLoaderIsUefi is set true, then
        one of isUefiBoot must also be
        set true"
        exit 1
      }
}

Write-Host "SUCCESS: Ok"
                
            

Windows Desktop 10 has a hostname maximum length of 15 characters.

if one of these Attune parameters are true, this step checks for the hostname length and fails if it is larger than 15. 1. isWin10Bios 2. isWin10Uefi

Execute the following script:

                
if ( ${{isWindowsWorkstation}} ) {

    $HOSTNAME = "{newOsNode.hostname}"
    
    $LENGTH = $HOSTNAME.length
    $MAX_LENGTH = 15
    
    if ( $LENGTH -gt $MAX_LENGTH ) {
        Write-Host "Length of hostname `"${HOSTNAME}`"  for Win10 is ${LENGTH} and can't be more than ${MAX_LENGTH}."
        false
    } else {
        Write-Host "Length of hostname `"${HOSTNAME}`" for Win10 is ${LENGTH} which is less than or equal to ${MAX_LENGTH}."
    }
    
} else {
    Write-Host "Not Windows Workstation, skipping."
}
                
            

  1. Checks if isWinPEKickstart is set true.
  2. If windowsFolderOnSamba is set to windows10, checks if one of these are set true * isWin10Bios * isWin10Uefi
  3. If windowsFolderOnSamba is set to one of windows2016, windows2019 or windows2022 checks if one of these are set true: * isWinServerBios * isWinServerUefi

Execute the following script:

                
if ( -Not ${{isWinPEKickstart}} ) {
    Write-Host "Please set isWinPEKickstart as the string 'true'"
    exit 1
}

if ( "{windowsFolderOnSamba}" -eq "windows10" ) {
    if ( -Not ${{isWindowsWorkstation}} ) {
        Write-Host "Please set one of 'isWindowsWorkstation' to true to install Win10."
        exit 1
    }
}

if (( "{windowsFolderOnSamba}" -eq "windows2016" ) -Or
    ( "{windowsFolderOnSamba}" -eq "windows2019" ) -Or
    ( "{windowsFolderOnSamba}" -eq "windows2022" )) {

    if ( -Not ${{isWindowsServer}} ) {
        Write-Host "Please set 'isWindowsServer' to true to install Windows Server."
        exit 1
    }
}

# Define the UNC path to the SMB share
$uncPath = "\\{sambaServerIpAddress}\share\{windowsFolderOnSamba}"

# Test if the path is accessible
if (Test-Path $uncPath) {
    Write-Host "The SMB share is accessible. Listing contents:"
    Get-ChildItem $uncPath
} else {
    Write-Host "The SMB share is not accessible or does not exist."
}
                
            

Deploys startnet.cmd.

This script is run by WinPE.

The startnet.cmd is run by WinPE. This script: 1. Installs drivers from "attune_drivers". 2. Sets the IP address. 3. Mounts the Samba server that hosts the extracted Windows ISOs as the "Z" drive. 4. Runs Windows setup.exe.

The Mako parameter "windowsFolderOnSamba" can have these values:

  • windows10
  • windows2016
  • windows2019
  • windows2022

Copy the File(s) WinPE_startnetcmd.tar to the target node.

{automationWorkerWindowsBaseDirectorySharePath}/build-{newOsNode.fqn}, relative to the home directory

Creates a post_install.wim Windows Imaging Format file on Windows Worker.

The purpose of this file is to overlay onto the C drive any files we want for the Windows Installer to use. In this case we want to deploy a post install setup PowerShell script at C:\post_install_setup.ps1 that is called by autounattend.xml <FirstLogonCommands>'s section.

This file is called by the "" section in the autounattend.xml file.

This script is run once post installation of the WIndows operating system.

Copy the File(s) Post_Install_Setup_PowerShell_Script.tar to the target node.

{automationWorkerWindowsBaseDirectorySharePath}/build-{newOsNode.fqn}/post_install_wim, relative to the home directory

Creates a post_install.wim file from the contents of post_install_wim on Windows Worker.

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"
$BUILD_DIR="$ISO_BUILD\build-{newOsNode.fqn}"

Set-Location $BUILD_DIR

Write-Host "We are in ${BUILD_DIR}"

$SOURCE="post_install_wim"
$WIMFILE="post_install.wim"

Write-Host "Creating ${WIMFILE} from directory ${SOURCE}."

dism /Capture-Image /ImageFile:$WIMFILE /CaptureDir:$SOURCE /Name:"post_install"

if (Test-Path -Path $WIMFILE) {
    Write-Host "WIM file created successfully at $destinationWIM"
} else {
    Write-Host "Failed to create WIM file."
}
                
            

Deploys the generic autounattend.xml.

Set one of these true depending on whether you want Windows Desktop 10 or Windows Server for BIOS or UEFI boot methods.

  1. isWin10Bios
  2. isWin10Uefi
  3. isWinServerBios
  4. isWinServerUefi

Set isWinPEKickstart to true for WinPE kickstarts.

Copy the File(s) Windows_Unattended_config_v2.tar to the target node.

{automationWorkerWindowsBaseDirectorySharePath}/build-{newOsNode.fqn}, relative to the home directory

Copies the skeleton WinPE folder C:\${WinPE_amd64} to C:\attuneautomationworker\build-{newOsNode.fqn}\WinPE_amd64.

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"
$BUILD_DIR="${ISO_BUILD}\build-{newOsNode.fqn}"

Set-Location "${BUILD_DIR}"

$WinPE_amd64="WinPE_amd64"

if ( -Not (Test-Path "${WinPE_amd64}") ) {
  New-Item "${WinPE_amd64}" -ItemType Directory
}

Copy-Item -Recurse -Path "${ISO_BUILD}\${WinPE_amd64}\*" `
    -Destination ".\${WinPE_amd64}\"
                
            

In the C:\attuneautomationworker\build-{newOsNode.fqn} folder, mounts ".\WinPE_amd64\media\sources\boot.wim to WinPE_BootImageDir using Dism on Windows Worker.

All files in WinPE_BootImageDir will be seen at X:\ drive when WinPE runs.

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"
$BUILD_DIR="${ISO_BUILD}\build-{newOsNode.fqn}"

Set-Location ${BUILD_DIR}

$WinPE_amd64="WinPE_amd64"
$WinPE_BootImageDir="WinPE_BootImageDir"

if ( -Not (Test-Path "${WinPE_BootImageDir}") ) {
  New-Item "${WinPE_BootImageDir}" -ItemType Directory
}

Dism /Mount-Image /ImageFile:".\${WinPE_amd64}\media\sources\boot.wim" `
  /Index:1 `
  /MountDir:".\WinPE_BootImageDir"
  
if ($LASTEXITCODE -ne 0) {
    Write-Error 'Failed to mount BOOT.WIM'
}
                
            

In the C:\attuneautomationworker\build-{newOsNode.fqn} folder, moves startnet.cmd to the folder WinPE_BootImageDir/Windows/System32.

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"
$BUILD_DIR="${ISO_BUILD}\build-{newOsNode.fqn}"

Set-Location "${BUILD_DIR}"

$STARTNET_FILE=".\WinPE_BootImageDir\Windows\System32\startnet.cmd"

Remove-Item ${STARTNET_FILE} -Force

Copy-Item -Path ".\startnet.cmd" `
    -Destination "${STARTNET_FILE}" `
    -Verbose

Copy-Item -Path ".\autounattend.xml" `
    -Destination ".\WinPE_BootImageDir" `
    -Verbose

$LOGO_PATH=".\WinPE_BootImageDir\Windows\Attune"
$LOGO="attune_logo.bmp"

if (-not (Test-Path -Path ${LOGO_PATH})) {
    New-Item -Path ${LOGO_PATH} -ItemType Directory
}

Copy-Item -Path ".\${LOGO}" `
    -Destination "${LOGO_PATH}\${LOGO}" `
    -Verbose

Copy-Item -Path ".\post_install.wim" `
    -Destination ".\WinPE_BootImageDir" `
    -Verbose
                
            

Copy drivers from the drop in directory C:\attuneautomationworker\drivers-{newOsNode.fqn} into C:\attuneautomationworker\build-{newOsNode.fqn}\WinPE_BootImageDir\drivers on Windows Worker.

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"
$BUILD_DIR="${ISO_BUILD}\build-{newOsNode.fqn}"

$WinPE_BootImageDir="WinPE_BootImageDir"

Set-Location "${BUILD_DIR}\${WinPE_BootImageDir}"

$DRIVERS="drivers"
if ( -Not (Test-Path "${DRIVERS}") ) {
  New-Item "${DRIVERS}" -ItemType Directory
}

$DRIVERS_DROP_IN_FOLDER="${ISO_BUILD}\drivers-{newOsNode.fqn}"

if (Test-Path "${DRIVERS_DROP_IN_FOLDER}") {
    
    Copy-Item -Recurse -Path "${DRIVERS_DROP_IN_FOLDER}\*" `
        -Destination "${DRIVERS}" `
        -Verbose
} else {
    Write-Host "Drivers drop in folder ${DRIVERS_DROP_IN_FOLDER} does not exist. No drivers copied."
}
                
            

Unmounts C:\attuneautomationworker\build-{newOsNode.fqn}\WinPE_BootImageDir using Dism.

This will write out changes back into C:\attuneautomationworker\build-{newOsNode.fqn}\WinPE_amd64\sources\boot.wim for both BIOS and UEFI boots.

Make sure there is no Windows File Explorer open at the mount directory.

If there is the unmount will fail and you need to manually run these commands to unmount it:

$ISO_BUILD="C:\attuneautomationworker"
$BUILD_DIR="$ISO_BUILD\build-{newOsNode.fqn}"

Set-Location $BUILD_DIR

Dism /Unmount-Image /MountDir:"./WinPE_BootImageDir" /discard

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"
$BUILD_DIR="${ISO_BUILD}\build-{newOsNode.fqn}"

Set-Location "${BUILD_DIR}"

$WinPE_BootImageDir = "WinPE_BootImageDir"

Dism /Image:"./WinPE_BootImageDir" `
    /cleanup-image `
    /StartComponentCleanup `
    /ResetBase
    
# Unmount the WinPE_BootImageDir folder back into BOOT.WIM
Dism /Unmount-Image /MountDir:"./WinPE_BootImageDir" /Commit
                
            

A compressed version of BOOT.WIM is generated called BOOT_CLEANED.WIM.

Relative to the C:\attuneautomationworker\build-{newOsNode.fqn} folder uses .\WinPE_amd64\media\sources\boot.wim to generate a compressed version at .\WinPE_amd64\sources\boot_cleaned.wim.

This step is for both BIOS and UEFI boots.

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"
$BUILD_DIR="${ISO_BUILD}\build-{newOsNode.fqn}"

Set-Location $BUILD_DIR

    $SourceImageFile = ".\WinPE_amd64\media\sources\boot.wim"
    $DestinationImageFile = ".\WinPE_amd64\media\sources\boot_cleaned.wim"
    
# Generate a compressed version of BOOT.WIM called BOOT_CLEANED.WIM
Dism /Export-Image /SourceImageFile:"${SourceImageFile}" `
  /SourceIndex:1 `
  /DestinationImageFile:"$DestinationImageFile" `
  /Compress:max `
  /Bootable `
  /CheckIntegrity
                
            

In the C:\attuneautomationworker\build-{newOsNode.fqn}\WinPE_amd64\sources folder, overwrites BOOT.WIM with BOOT_CLEANED.WIM and deletes BOOT_CLEANED.WIM.

This step applies to both BIOS and UEFI boot methods.

Execute the following script:

                
$ISO_BUILD="{automationWorkerWindowsBaseDirectory}"

$WINPE_STAGING_SOURCES_DIR="${ISO_BUILD}\build-{newOsNode.fqn}\WinPE_amd64\media\sources"

Set-Location "${WINPE_STAGING_SOURCES_DIR}"

Write-Host "Before"
dir

$BOOT_CLEANED_WIM="BOOT_CLEANED.WIM"

Copy-Item -Path ".\${BOOT_CLEANED_WIM}" `
    -Destination ".\BOOT.WIM"
    
Remove-Item ".\${BOOT_CLEANED_WIM}"

Write-Host "After"
dir
                
            

  1. Starts the Deployment and Imaging Tools Environment by executing DandISetEnv.bat. The call is needed so more batch commands can be run afterwards. call "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat"
  2. After running DandISetEnv.bat by default the directory will change to: C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools> The directory path is changed to C:\attuneautomationworker\build-{newOsNode.fqn}. cd C:\attuneautomationworker\build-{newOsNode.fqn}
  3. Run MakeWinPEMedia to take the modified copy of the skeleton WinPE files at C:\attuneautomationworker\build-{newOsNode.fqn}\WinPE_amd64 and generate the ISO at C:\attuneautomationworker\kickstart_{newOsNode.fqn}.iso.

Execute the following script:

                
call "C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat" dir
dir

cd {automationWorkerWindowsBaseDirectory}\build-{newOsNode.fqn}
dir

del ..\kickstart_{newOsNode.fqn}.iso

MakeWinPEMedia /ISO .\WinPE_amd64 ..\kickstart_{newOsNode.fqn}.iso
                
            

Completed

You have completed this instruction.

Attune - Powered by ServerTribe

Automate with Attune

Download the Attune Community Edition.

DOWNLOAD!!!

Discuss this Project in Discord

Join our Discord channel and connect with like-minded individuals who share your passion. Engage in lively discussions, gain valuable insights, and stay updated on the latest trends in our industry. Don't miss out on this opportunity to network, learn, and grow together.


Click the link below and become a part of our vibrant community on Discord today!

Join NOW!!!