Step 1

Create the VM

One script creates the virtual machine with the settings TrueNAS needs: fixed memory, Secure Boot off, a small disk for TrueNAS and four separate disks for storage.

5 minutesRun as administrator on the Hyper-V host

Set the names and paths

Change the three lines to match your host.

Hyper-V host
$vm   = 'CON-NAS-01'
$root = 'D:\VMs'
$iso  = 'D:\ISOs\TrueNAS.iso'

Create the VM and its disks

Hyper-V host
New-VM -Name $vm -Generation 2 -MemoryStartupBytes 8GB -Path $root `
    -NewVHDPath "$root\$vm\Virtual Hard Disks\$vm.vhdx" -NewVHDSizeBytes 20GB -SwitchName 'CON-LAN' | Out-Null
Set-VM -Name $vm -ProcessorCount 2 -StaticMemory -CheckpointType Disabled -AutomaticStopAction ShutDown
Set-VMFirmware -VMName $vm -EnableSecureBoot Off

foreach ($i in 1..4) {
    $path = "$root\$vm\Virtual Hard Disks\$vm-DATA-{0:D2}.vhdx" -f $i
    New-VHD -Path $path -SizeBytes 80GB -Dynamic | Out-Null
    Add-VMHardDiskDrive -VMName $vm -ControllerType SCSI -Path $path
}

The boot disk takes the VM's name, CON-NAS-01.vhdx. The storage disks are numbered CON-NAS-01-DATA-01.vhdx to -DATA-04.vhdx, so you can tell them apart on the host.

SettingWhy
8 GB, fixedTrueNAS uses memory to speed up its disks, and it expects the amount to stay the same.
Secure Boot offThe TrueNAS installer will not start with Hyper-V's default Secure Boot setting.
Checkpoints offRolling a storage server back in time can damage what is stored on it.
Separate storage disksTrueNAS takes the whole of the disk it is installed on, so storage needs disks of its own. Four lets you use RAIDZ2, which survives two failing.

Add the network cards

The first card is for management. The other two carry storage traffic on their own VLANs. Leave those two lines out if you only plan to share folders.

Hyper-V host
Rename-VMNetworkAdapter -VMName $vm -Name 'Network Adapter' -NewName 'Mgmt'
Set-VMNetworkAdapterVlan -VMName $vm -VMNetworkAdapterName 'Mgmt' -Access -VlanId 30

foreach ($c in @{N='iSCSI-A';V=61}, @{N='iSCSI-B';V=62}) {
    Add-VMNetworkAdapter -VMName $vm -SwitchName 'CON-LAN' -Name $c.N
    Set-VMNetworkAdapterVlan -VMName $vm -VMNetworkAdapterName $c.N -Access -VlanId $c.V
}

Attach the installer

Hyper-V host
Add-VMDvdDrive -VMName $vm -Path $iso
Set-VMFirmware -VMName $vm -FirstBootDevice (Get-VMDvdDrive -VMName $vm)

Check it

Hyper-V host
Test-Path $iso
Get-VM $vm | Format-List Name, Generation, ProcessorCount, @{n='RAM_GB';e={$_.MemoryStartup/1GB}}, CheckpointType
Get-VMHardDiskDrive -VMName $vm | Format-Table ControllerLocation, Path -AutoSize
Get-VMNetworkAdapterVlan -VMName $vm | Format-List ParentAdapter, OperationMode, AccessVlanId

Done when

Check

Test-Path returns True, the VM shows Generation 2 with 8 GB and checkpoints disabled, five disks are listed, and each network card shows Access mode on its VLAN.

Your progress is kept in this browser only.