layout | title |
---|---|
post |
How to Create a Linux Virtual Server in Hyper V with Powershell |
Now that we have enabled Hyper V we can utilize the built in Hyper V module. At the time of this post the Hyper V Module contains 232 commands, which is a rather robust module providing a lot of functionality.
We will need to leverage the help documentation for this module to better understand the Functions we have at our disposal. I find it useful to review all the commands in a new module to get a feel for what it is capable of. You can gather a lot just from the name of the command, however sometimes the command doesn't always do what we expect it to do. This is where the help documentation comes into play.
Update-Help
Now that our help files are up to date let's take a look at the first command we will want to use.
Get-Help -Name New-VHD
Before we can create a new VM we will first need to create a virtual hard drive.
New-VHD -Dynamic -Path $VHDPath -SizeBytes 2e+10
Now that we have our VHD ready let's create a new Virtual Machine and attach our VHD
New-VM -Name $VMName -VHDPath $VHDPath -Path $VMPath
Our new VM has been created let's check on the default configuration.
Get-VM -Name $VMName | Select-Object -Property *
We will eventually want our new VM to connect to the internet, so lets create and add a VMSwitch.
New-VMSwitch -Name $VMSwitchName -SwitchType Internal |
Set-VMSwitch -NetAdapterName Ethernet
Now that we have a Virtual Switch created we will need to configure the VM to use our switch.
Get-VM -Name $VMName |
Get-VMNetworkAdapter |
Connect-VMNetworkAdapter -SwitchName $VMSwitchName
We will need to run an Operating System on our new VM, you can use your favorite but for this post I will use Ubuntu Studio. We will be using this VM for a few more exercises and we will need Ubuntu. Click here for Microsofts Best Practices for running Linux on Hyper-V.
Get-VMDvdDrive -VMName $VMName |
Set-VMDvdDrive -Path $OsIsoPath
Start-VM -VMName $VMName
Unfortunately the process to install the Linux OS requires some manual intervention. I will revisit how I install Linux at a later time so we can fully automate this server setup.
We have barely scratched the surface of the Hyper-V Powershell module in this post. Microsoft has given us some very powerful tools built right into Windows 10 for free. I hope to have time to learn more when I revisit this module for later projects.