Skip to content

Windows 11 VDI Template Build

This goes over the semi automated process of building a template for VDI based on Windows 11.

1.0 Prerequisite

  1. OSD Server (Operating System Deployment)
  2. NAAS Server

2.0 Build Process

The follwing Powershell Code will:

  1. Connect to vCenter
  2. Create a New VM named VDI-WIN11-23H3
  3. Set the Mac Address to: 00:50:56:3f:00:00
  4. Power on the VM
  5. Wait for VM build to finish
  6. Convert to a VM Template
  7. Publish it to the Content Libary for replication to other sites
# Connect to the vCenter server
Connect-VIServer -Server "your_vcenter_server" -User "your_username" -Password "your_password"

$vmName = "VDI-WIN11-23H3"

$newVMSplatting = @{
    Name      = $vmName
    Datastore = (Get-Datastore -Name "WL*vsan")
    Location  = (Get-Folder -Name "Templates")
    Portgroup = Get-VDPortgroup -Name "Angel VDI Users"
    NumCpu    = 2
    MemoryGB  = 16
    VMHost    = (Get-VMHost -Location (Get-Cluster -Name "E06*") | Get-Random)
    DiskGB    = 90
    GuestId   = "windows11_64Guest"
}

# Create the new VM
New-VM @newVMSplatting

# Get the newly created VM
$vm = Get-VM -Name $vmName

$nic = Get-NetworkAdapter -VM $vm
Set-NetworkAdapter -NetworkAdapter $nic -MacAddress "00:50:56:3f:00:00" -StartConnected $true -Confirm:$false
Get-ScsiController -VM $vm | Set-ScsiController -Type ParaVirtual

Start-Vm $vm

Start-Sleep -Seconds 900

while ((Get-VM $vm).PowerState -eq 'PoweredOn') {
    Start-Sleep -Seconds 60
}
Set-VM -VM $vm -ToTemplate -Confirm:$false
$template = Get-Template -Name $vmName
$newContentLibraryItem = @{
    ContentLibrary = (Get-ContentLibrary -Name "Main")
    Name           = "$(Get-Date -Format yyyy-MMM) Windows 11 23H3"
    Template       = $template
}
New-ContentLibraryItem @newContentLibraryItem
Remove-Template -Template $vmName -Confirm:$false

3.0 Scheduled Task

The above powershell code runs on the NAAS Server as a Scheduled task. The Scheduled Task should run every Second Thursday of the month. The scheduled task should run using the NETWORK SERVICE account and does not need to run with highest privileges.

Make sure you update the vcenter account above to a service account.