pf-VM.ps1
function New-VM_Windows10 { $Server = "Windows10" #Create VM name as Windows10 $ServerRAM = 4GB #Set RAM size to 1 GB $ServerVHD = 60GB #Set VHD size to 80GB $VMLOC = "C:\VM" #Define where the virtual hard disk file is stored $Switch = "External" #Define the name of the virtual switch #Specify where to install the ISO file $isoFile = "C:\Installers\en-gb_windows_10_consumer_editions_version_2004_x64_dvd_d4d263d8.iso" # Create folders and virtual throw switches for virtual machines mkdir $VMLOC -ErrorAction SilentlyContinue $TestSwitch = Get-VMSwitch -Name $Switch -ErrorAction SilentlyContinue; if ($TestSwitch.Count -EQ 0){New-VMSwitch -Name $Switch -SwitchType Private} # Create a new virtual machine New-VM -Name $Server -Path $VMLOC -MemoryStartupBytes $ServerRAM ` -NewVHDPath $VMLOC\$ServerVHD.vhdx -NewVHDSizeBytes $ServerVHD -SwitchName $Switch # Configuring a virtual machine Set-VMDvdDrive -VMName $Server -Path $isoFile #Start the Virtual Machine Start-VM $Server } |