Skip to content

Instantly share code, notes, and snippets.

@bitfrickler
Created November 24, 2017 13:52
Show Gist options
  • Save bitfrickler/49268603f2f87016f55098255d1c80dc to your computer and use it in GitHub Desktop.
Save bitfrickler/49268603f2f87016f55098255d1c80dc to your computer and use it in GitHub Desktop.
function Create-VM {
param(
[Parameter(Mandatory=$true)][string]$Name,
[Parameter(Mandatory=$false)][int64]$Memory=1024MB,
[Parameter(Mandatory=$false)][int64]$MemoryMinimum=1024MB,
[Parameter(Mandatory=$false)][int64]$MemoryMaximum=2048MB,
[Parameter(Mandatory=$false)][int64]$CpuCount=1,
[Parameter(Mandatory=$false)][uint64]$DiskSize=64GB,
[Parameter(Mandatory=$false)][string]$Location=".",
[Parameter(Mandatory=$false)][string]$BootISO
)
New-Item -ItemType Directory -Path "$Location\$Name\Virtual Hard Disks" -Force
New-VHD -Path "$Location\$Name\Virtual Hard Disks\$($Name)_disk1.vhdx" -SizeBytes $DiskSize
New-VM -Name "$Name" -MemoryStartupBytes $Memory -VHDPath "$Location\$Name\Virtual Hard Disks\$($Name)_disk1.vhdx" -Generation 2 -Switch "intern (10.3.9.0)"
Set-VM -Name "$Name" -AutomaticCheckpointsEnabled $false -ProcessorCount $CpuCount -DynamicMemory -MemoryMinimumBytes $MemoryMinimum -MemoryMaximumBytes $MemoryMaximum
Add-VMScsiController -VMName $Name
Add-VMDvdDrive -VMName "$Name" -Path "$BootISO"
$DvdDrive = Get-VMDvdDrive -VMName $Name
Set-VMFirmware -VMName $Name -FirstBootDevice $DvdDrive
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment