How to Create Windows Server 2022 (Win2022) autounattend Dual 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 Server 2022 (Win2022) autounattend Dual 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.

Checks if at least one of isWinServerBios or isWinServerUefi is set tot true.

Connect via RDP:

mstsc /admin /v:{automationworkerwindowsnode}

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

Execute the following script:

                
if ((-Not ${{isWinServerBios}}) -and `
    (-Not ${{isWinServerUefi}})) {
    Write-Host "Please set one of 'isWinServerBios' or 'isWinServerUefi' to true to install Windows Server 2016, 2019 or 2022."
    exit 1
} else {
    Write-Host "Ok."
}
                
            

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
    }
}
                
            

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
    }
}
                
            

Check if Windows Subsystem for Linux is installed.

Execute the following script:

                
wsl --list

if (echo $?) {
    Write-Host "WSL is installed."
} else {
    Write-Host "WSL is not installed."
    exit 1
}
                
            

Deletes the folder at C:\attuneautomationworker\build-{newOsNode.fqn}.

Execute the following script:

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

if (Test-Path $DIR) {
    Remove-Path -Recursive $DIR
}
                
            

Deploys Windows Server 2022 ISO to /c$/attuneautomationworker/build-winpe-iso.

Download from https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2022.

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

Deploy the File(s) here:

/c$/attuneautomationworker/build-{newOsNode.fqn}

Extracts the boot.img from the ISO. This is required for passing to mkisofs to regenerate a bootable BIOS ISO.

Only applies to BIOS kickstarts so if any of these parameters are set the string true:

  1. isWin10Bios
  2. isWinServerBios

The bash script file needs to have the Windows default carriage return line feed CRLF replaced with Linux default line feeds LF https://stackoverflow.com/questions/19127741/replace-crlf-using-powershell.

Execute the following script:

                
if ((${{isWin10Bios}}) -or `
    (${{isWinServerBios}})) {

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


  Set-Location $BUILD_DIR

  $scriptContent=@'
# Case insensitve globbing
shopt -s nocaseglob;
# Set the filename of the ISO
F=$(ls *.iso);
# Get the Boot image offset
OFFSET=`isoinfo -d -i $F | grep Bootoff | cut  -c21-`;
# Extract the boot.img.
dd if=$F of=boot.img bs=2048 count=8 skip=$OFFSET;
'@

    # Replace CRLF with LF
    $scriptContent = $scriptContent.replace("`r`n","`n")
    
    $FILE = "attune_wsl_extract_boot_img.sh"
    
    Set-Content -Path $FILE -NoNewline -Value $scriptContent

    wsl -d Ubuntu --user root --exec bash "${FILE}"

    if ($LASTEXITCODE -ne 0) {
        Write-Error 'Failed to extract boot.img'
    }
    
    Remove-Item "${FILE}"

} else {
    Write-Host "Skipping for UEFI ISO creation."
}
                
            

Extracts the Windows ISO.

Execute the following script:

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

Set-Location $BUILD_DIR

$ISO_WILDCARD="*.iso"

if (test-Path "${ISO_WILDCARD}" -pathtype leaf) {
    $ISO=(dir $ISO_WILDCARD).name
    Write-Host "Found ISO ${ISO}. Extracting it."
    
    & 'C:\Program Files\7-Zip\7z.exe' x ".\${ISO}"
    
    Write-Host "Removing ${ISO}"
    Remove-Item "${ISO}"

} else {
	Write-Error "No ISO found for extracting."
}
                
            

From https://serverfault.com/questions/353826/windows-boot-iso-file-without-press-any-key this disables the "Press any key To boot from CD or DVD . . . .".

efisys_noprompt.bin does not have the prompt "Pres any key to boot from CDROM".

Execute the following script:

                
if ( ${{isWin10Uefi}} -or ${{isWinServerUefi}} ) {

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

    Set-Location $BUILD_DIR

    Set-Location efi\microsoft\boot
    
    Copy-Item -Path .\efisys_noprompt.bin -Destination .\efisys.bin
} else {
    Write-Host "Skipping for BIOS ISO creation."
}
                
            

Creates a BIOS bootable Windows ISO called kickstart_{newOsNode.fqn}.iso from the contents in folder C:\attuneautomationworker\build-{newOsNode.fqn}.

Only applies BIOS kickstarts so if any of these parameters are set the string true:

  1. isWin10Bios
  2. isWinServerBios

Execute the following script:

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

# This is so we place the "attune_wsl_create_bios_boot_iso.sh" outside the $BUILD_FOLDER
Set-Location $ISO_BUILD

if (${{isWin10Bios}} -or `
    ${{isWinServerBios}}) {

    $scriptContent=@"
mkisofs \
    -b boot.img \
    -no-emul-boot \
    -c BOOT.CAT \
    -iso-level 3 \
    -udf \
    -joliet-long \
    -relaxed-filenames \
    -allow-limited-size \
    -J \
    -full-iso9660-filenames \
    -disable-deep-relocation \
    -omit-version-number \
    -V "KS_WIN" \
    -o kickstart_{newOsNode.fqn}.iso \
    '${BUILD_FOLDER}'
"@
    # Replace CRLF with LF
    $scriptContent = $scriptContent.replace("`r`n","`n")
    
    $FILE = "attune_wsl_create_bios_boot_iso.sh"

    Set-Content -Path $FILE -NoNewline -Value $scriptContent

    wsl -d Ubuntu --user root --exec bash "${FILE}"

    if ($LASTEXITCODE -ne 0) {
        Write-Error 'Failed to create $ISO_BUILD\kickstart_{newOsNode.fqn}.iso'
    }
      
    Remove-Item "${FILE}"

} else {
    Write-Host "Skipping for UEFI boot."
}
                
            

Creates a UEFI bootable Windows ISO called kickstart_{newOsNode.fqn}.iso from the contents in folder C:\attuneautomationworker\build-{newOsNode.fqn}.

Only applies to UEFI kickstarts so if any of these parameters are set the string 'true':

  1. isWin10Uefi
  2. isWinServerUefi

Execute the following script:

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

# This is so we place the "tmpBash.sh" outside the $BUILD_FOLDER
Set-Location $ISO_BUILD

if (${{isWin10Uefi}} -or `
    ${{isWinServerUefi}}) {

    $scriptContent=@"
mkisofs \
    -allow-limited-size \
    -iso-level 4 \
    -full-iso9660-filenames \
    -rock \
    -b boot/etfsboot.com \
    -no-emul-boot \
    -boot-load-seg 0 \
    -boot-load-size 8 \
    -hide boot.catalog \
    -eltorito-alt-boot \
    -no-emul-boot \
    -b efi/microsoft/boot/efisys.bin \
    -boot-load-size 1 \
    -udf \
    -untranslated-filenames \
    -disable-deep-relocation \
    -o kickstart_{newOsNode.fqn}.iso \
    '${BUILD_FOLDER}'
"@

    # Replace CRLF with LF
    $scriptContent = $scriptContent.replace("`r`n","`n")
    
    $FILE = "attune_wsl_create_uefi_boot_iso.sh"

    Set-Content -Path $FILE -NoNewline -Value $scriptContent

    wsl -d Ubuntu --user root --exec bash "${FILE}"

    if ($LASTEXITCODE -ne 0) {
        Write-Error 'Failed to extract boot.img'
    }

} else {
    Write-Host "Skipping for BIOS boot."
}
                
            

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

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

Copies the contents of the drivers drop in folder at C:\attuneautomationworker\drivers-{newOsNode.fqn} to C:\attuneautomationworker\build-{newOsNode.fqn}\drivers.

Execute the following script:

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

Set-Location "${BUILD_DIR}"

$DRIVERS_DROP_IN_FOLDER = "C:\attuneautomationworker\drivers-{newOsNode.fqn}"
$DESTINATION_DRIVERS_FOLDER = "drivers"

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

if ( Test-Path "${DRIVERS_DROP_IN_FOLDER}" ) {

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

Creates an ISO at {automationWorkerLinuxBaseDirectory}/drivers_{newVmNode.fqn}.iso containing:

  1. drivers folder
  2. autounattend.xml
  3. post_install_setup.ps1

This works for kickstarts on Windows Worker with: 1. Windows Desktop 10 2. Windows Server 2016 2. Windows Server 2019 3. Windows Server 2022

Execute the following script:

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

# This is so we place the "attune_wsl_create_answer_file_iso.sh" outside the $DRIVERS_FOLDER
Set-Location "${BUILD_DIR}"

$DRIVERS_FOLDER="drivers"
$DRIVERS_ISO_NAME="drivers_{newOsNode.fqn}.iso"

    $scriptContent=@"
mkisofs \
    -o "../${DRIVERS_ISO_NAME}" \
    -iso-level 3 -udf -joliet-long -relaxed-filenames \
    -J -l -D -N -V "DRIVERS" "${DRIVERS_FOLDER}" \
    autounattend.xml post_install_setup.ps1
"@

# Replace CRLF with LF
$scriptContent = $scriptContent.replace("`r`n","`n")
    
$FILE = "attune_wsl_create_answer_file_iso.sh"

Set-Content -Path $FILE -NoNewline -Value $scriptContent

wsl -d Ubuntu --user root --exec bash "${FILE}"

if ($LASTEXITCODE -ne 0) {
    Write-Error 'Failed to create $ISO_BUILD\${DRIVERS_ISO_NAME}'
}
  
Remove-Item "${FILE}"
                
            

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!!!