Last active
January 3, 2018 05:29
-
-
Save TechnologistAU/198e2ffd3a0c16a969a85467360e3dee to your computer and use it in GitHub Desktop.
Create a Hyper-V Virtual Machine suitable for running Debian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Creates a Hyper-V Virtual Machine suitable for running Debian. | |
.DESCRIPTION | |
This PowerShell script creates a new Hyper-V Generation 2 Virtual Machine | |
that is suitable for installing and running Debian. The default hardware | |
configuration set by this script is as follows: | |
- 4 Processor Cores | |
- 2GB Static Memory | |
- 127GB Dynamic Hard Disk | |
- 1 Network Adapter | |
In addition, a virtual DVD device is added for to the Debian installation | |
ISO file. | |
.NOTES | |
File Name : Debian_Hyper-V.ps1 | |
Author : Chris Lowe | |
Prerequisite : PowerShell V2 | |
.LINK | |
http://www.technologist.site | |
.EXAMPLE | |
Debian_Hyper-V.ps1 | |
#> | |
# Adjust the following variable values as required | |
$VM_Name = "Debian 8.5.0" | |
$VM_ISO = "C:\ISO\debian-8.5.0-amd64-netinst.iso" | |
$VM_ProcessorCores = 4 | |
$VM_MemorySize = 2GB | |
$VM_DiskSize = 127GB | |
$VM_DiskPath = (Get-VMHost).VirtualHardDiskPath | |
$VM_Adapter = (Get-NetAdapter -Physical | Where-Object {$_.Status -eq 'Up'} | Sort-Object $_.LinkSpeed | Select-Object -First 1).Name | |
If (((Get-VMSwitch -SwitchType External).Name) -eq $null) {New-VMSwitch -Name 'External' -NetAdapterName $VM_Adapter -AllowManagementOS $true -Notes 'External Switch'} | |
$VM_Switch = (Get-VMSwitch -SwitchType External).Name | |
# Create a new Virtual Hard Disk using 1MB Block Size as per Microsoft's Recommendations | |
# https://technet.microsoft.com/en-us/library/dn720239.aspx | |
New-VHD -Path $VM_DiskPath\$VM_Name.vhdx -SizeBytes $VM_DiskSize –Dynamic –BlockSizeBytes 1MB | |
# Create a new Virtual Machine | |
New-VM -Name $VM_Name -Generation 2 -MemoryStartupBytes $VM_MemorySize -VHDPath $VM_DiskPath\$VM_Name.vhdx -SwitchName $VM_Switch | |
Set-VM -VMName $VM_Name -ProcessorCount $VM_ProcessorCores -StaticMemory -Notes "$VM_Name`r`nCreated:`t$((Get-Date).ToString())`r`nSource:`t$(Split-Path $VM_ISO -Leaf)" | |
# Add a virtual DVD device for the installation ISO | |
Add-VMDvdDrive -VMName $VM_Name -Path $VM_ISO | |
# Configure UEFI Firmware to disable "Secure Boot" and "Boot from DVD" | |
Set-VMFirmware -VMName $VM_Name -EnableSecureBoot Off -FirstBootDevice (Get-VMDvdDrive -VMName $VM_Name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment