Skip to content

Instantly share code, notes, and snippets.

@PixelRobots
Created April 21, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PixelRobots/e2121985c9662a99a20139fcad3b6724 to your computer and use it in GitHub Desktop.
Save PixelRobots/e2121985c9662a99a20139fcad3b6724 to your computer and use it in GitHub Desktop.
$VMName = "PIXEL-SRV01"
[int64]$VMMem = 1MB*1024 #chnage to 1gb* the number of gb if you need.
$VMGen = "2"
$VHDPath = "V:\Hyper-V\$VMname\Virtual Hard Disks\$VMName.VHDX"
$VMPath = "V:\Hyper-V\"
[int64]$VMSize = 1GB*40
$ISOPath = "C:\ISO\en_windows_server_2016_x64_dvd_9327751.iso"
new-vm -Name $VMName -path $VMPath -MemoryStartupBytes $VMMem -Generation $VMGen -NewVHDPath $VHDPath -NewVHDSizeBytes $VMSize -BootDevice vhd
Add-VMDvdDrive $VMName
Start-Sleep -Seconds 5
Set-VMDvdDrive -VMName $VMName -Path $ISOPath -ToControllerNumber 0 -ToControllerLocation 1
Start-Sleep -Seconds 5
$dvd = Get-VMDvdDrive -VMName $VMName
Set-VMFirmware -VMName $VMName -FirstBootDevice $dvd
Start-Sleep -Seconds 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment