Datacenter

Working in the Datacenter – Add-DVDDrive does not work correctly in Windows Server 2016 TP4 (or in Windows 10)

Update 2015-12-17 : This is now a confirmed bug, and as soon as I know more I will update this post.

It seems to be a bug, hopefully it will be fixed soon. The issue is very simple. If you try to run Add-VMDvdDrive the –path must be specified, in previous version that could be left alone. This problem is more common when you create VM Gen 2, since it does not have a DVD by default, and yes when we build VM’s they usually have a empty DVD for various reasons. According to help in the command let, there is no differences in the cmdlet between 1.1 and 2.0, but in reality it is.

The Issue

The problem is that when using the command Add-VMDvdDrive -VMName $VMName it fails with Add-VMDvdDrive : Exception of type ‘System.ArgumentException’ was thrown because it does not have a path, so i have seen workarounds when you create a small ISO and mount that and then you can remove that, but that sucks. There are some other issues as well.

image
The issue.

The Workaround

Luckily there is 2 different PowerShell modules, 1.1 for older OS and 2.0 for Windows 10/Windows server 2016 TP4 so the only thing you need to do is unload the new PowerShell module for Hyper-V and load the old one, and when you are done, you can load the new module again.

(if you would like to know why there is 2 versions, here you go: http://blogs.msdn.com/b/virtual_pc_guy/archive/2015/11/16/why-are-there-two-hyper-v-powershell-modules-in-windows-10.aspx)

image
We run this in the beginning of the script to replace the module.

image
We run this in the end of the script to restore the module.

/mike

Here is the code on GHitHub

# Check Build Version
# Due to a minor bug in the Hyper-V module 2.0 we need to replace that with the old version when creating VM's that uses Add-VMDvdDrive
if($PSVersionTable.BuildVersion.Major -eq 10){
Write-Output "Note: Running on $($PSVersionTable.BuildVersion) and therefore we need to change to Hyper-V module 1.1"
Write-Output "Unloading Hyper-V module 2.0 and loading Hyper-V module 1.1"
Remove-Module Hyper-V -Force
Import-Module Hyper-v -RequiredVersion 1.1 -Force
Get-Module -Name Hyper-V
}
if($PSVersionTable.BuildVersion.Major -eq 10){
Write-Output "Note: Running on $($PSVersionTable.BuildVersion) and therefore we need to change back to Hyper-V module 2.0"
Write-Output "Unloading Hyper-V module 1.1 and loading Hyper-V module 2.0"
Remove-Module Hyper-V -Force
Import-Module Hyper-v
Get-Module -Name Hyper-V
}
view raw gistfile1.txt hosted with ❤ by GitHub

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.