Introduction
Recently I was involved in getting a bunch of “holy cow” virtual machines updated/migrated to be future ready (shielded VMs, see Guarded fabric and shielded VMs overview).
That means they have to be on Windows 2012 R2 as the guest OS minimally .For us anyway, we’re not falling behind the curve OS wise. That’s the current legacy OS in the environment. Preferably they need to be at Windows Server 2016. This is has been taken care of and 40% of the virtual machines is already running Windows Server 2016 for the Guest OS, the remainder is at Windows Server 2012 R2 and those are moving to Windows Server 2016, where useful and possible, at a steady pace.,
When deploying new virtual machines the default is to use generation 2 virtual machines. Any remaining virtual machines that cannot be replaced need to be converted to generation 2. For that we routinely use the great script provided by Microsoft’s John Howard (see Hyper-V generation 2 virtual machines – part 10) We’ll share some tips on using Convert-VMGeneration.ps1 with Windows Server 2016, which is an OS / Hyper-V version later than what the script was written for and tested against.
Tips on using Convert-VMGeneration.ps1 with Windows Server 2016
During the use of this script we came across a couple of new situations for us. One of those were Window Server 2016 virtual machines that are still generation 1 and reside on either a Windows Server 2012 (R2) or Windows Server 2016 host. Another were virtual machines with Windows Server 2012 R2 or Windows Server 2016 as a guest OS that already live on Windows Server 2016 and are still generation 1 and have either already been converted to or installed on a virtual machine version 8 or not (still at 5). All these can be death with successfully.
Situation 1
Running the script on a Windows Server 2016 Host. This throws an error reporting that the was only tested with PS version 4.
This is easily dealt with by using the -noPSVersionCheck switch, it even tells you to do so in the error message. I have found no issues in doing so.
.\Convert-VMGeneration.ps1 -VMName “MyVM” -path “C:\ClusterStorage\Volume1\ConvertedMyVM” -NoPSVersionCheck
Situation 2
Running the script against a generation 1 virtual machine with a Windows Server 2016 guest OS required a little adaptation of the script as it has an issue with detecting the guest OS version as supported. This is due to the fact that in the script the check is done against string values and they generate a logical “bug” when the doing.
Checking if a string of value 7 -lt 6 will evaluate correctly but doing the same with 10 doesn’t, that’s false. An error message is show that the “Source OS must be version 6.2 (Windows 8/Windows Server 2012) or later”. Well is most certainly is, but the 10 in 10.0.14393.206 is not seen as greater or equal to six.
We fixed by converting the 1st and 2nd part (for good measure) of the OS version string to an integer before the check happens. That fixes it for us.
We’ll demonstrate this in a code snippet to run on a Windows Server 2016 host.
$SourceNTDLL = "C:\windows\system32\ntdll.dll" $script:ProgressPoint = 651 $SourceOSVersion = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($SourceNTDLL).FileVersion) $script:ProgressPoint = 652 $SourceProductName = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($SourceNTDLL).ProductName) $SourceOSVersionParts = $SourceOSVersion.split(".") if ($SourceOSVersionParts[0]-lt 6) { Write-Host "Source OS must be version 6.2 (Windows 8/Windows Server 2012) or later." } if (($SourceOSVersionParts[0] -eq 6) -and ($SourceOSVersionParts[1] -lt 2)) {Write-Host "Source OS must be version 6.2 (Windows 8/Windows Server 2012) or later." }
This will give you the massage that the “Source OS must be version 6.2 (Windows 8/Windows Server 2012) or later”. So, we cast the $SourceOSVersionParts[X] variables to an integer to overcome this.
$SourceNTDLL = "C:\windows\system32\ntdll.dll" $script:ProgressPoint = 651 $SourceOSVersion = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($SourceNTDLL).FileVersion) $script:ProgressPoint = 652 $SourceProductName = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($SourceNTDLL).ProductName) $SourceOSVersionParts = $SourceOSVersion.split(".") #Cast the OS version parts to an integer $OSVersionPart1 =[INT]$SourceOSVersionParts[0] $OSVersionPart2 =[INT]$SourceOSVersionParts[1] If ($OSVersionPart1 -lt 6) { Write-Host -ForegroundColor Green "Source OS must be version 6.2 (Windows 8/Windows Server 2012) or later." } if (($OSVersionPart1 -eq 6) -and ($OSVersionPart2 -lt 2)) { Write-Host "Source OS must be version 6.2 (Windows 8/Windows Server 2012) or later." }
Do this and it evaluates correctly now so your script will run. That’s the only adaption we had to make in the script to make it run with a Windows Server 2016 guest OS. Note that the snippet is for demo purposes. The real script needs to fixed using this logic.
Situation 3
My virtual machine is already a version 8 VM but still a generation 1 virtual machine. That’s not a problem at all. As long as you deal with situation 1 and 2, it will convert correctly.
Conclusion
If you’re prepping legacy virtual machines that need to be moved into a modern private cloud or on premises deployment you might need to convert them to generation 2 in order to take full advantage of the capabilities of the current Hyper-V platform (i.e. Shielded VMs). To do so you’ll be fine as long as they are running Windows Server 2012 (R2) as a guest OS on a Windows 2012 R2 host. If not, some creativity is all you need to get things going. Upgrade the guest OS if needed and fix the script if you encounter the situations as we described above. Sure, we have to herd virtual machines as cattle and avoiding holy cows VMs is important. But they do still exist and if they provide valuable services and we can’t let this hold us back from moving ahead. By proceeding like we did we prevented just that and avoided upsetting too many processes and people in the existing situation, let alone hindering them in the execution of their job. We still arrived at a situation where the virtual machines can be hosted as shielded virtual machines. Good luck!
Pingback: ИТ Вестник №02/03.2017 | Блог IT-KB
Where can I download this Convert-VMGeneration script? I can not find a place to download it anymore.
Only a quick Google way: https://github.com/Desmont/PowerShell-Scripts/blob/master/Convert-VMGeneration.ps1
Hello,
Thanks for the great instructions
I’ve a question does the above modification for windows 2016 guest working with windows server 2019 guest too ? or needs another code modification.
Thanks again
It should but it has been a while. Easy to test, comment out the actual conversion and just see if the logic works for you.
Hello,
The converting works fine sometimes
But I’m facing issue where the mounted volumes when the script finished it remains y drive in windows explorer. And when I use the script again to convert Another Gen1 VM it fails due the y drive. In disk management or disk part there is no anything related to Y drive and I had to reboot the host server to solve the issue is there any workaround for this issue.
Another issue when converting 2012r2 vm in apply wim step it fails with the below error
DISM: /Apply-Image /ImageFile:C:\image\image2.wim /Index:1 /ApplyDir:Z\ failed deployment image servicing and management tool version: 10.0.17763.1697 error code 1299 indicates a particular security id may not be assigned as the label of an object
Thanks in advance
1) Yes, that is a issue since Windows Server 2016. I did reach out to MSFT but this was never addressed. What you can do I adapt the script and use free drive letters. But to get rig of them a raboot seems the only decemt fix. WUse different letters also helps run multiple transformations in parallel.
2) Sounds like a scurity issue somewhere. I would try DISM in the VM to see if that gives issue or fixes issues: https://docs.microsoft.com/en-us/troubleshoot/windows-server/deployment/fix-windows-update-errors. I have converted W2K12R2 machine on W2K19 hosts so that shloud not be an issue.
Thanks for for your reply and help I will try to run dism inside the VM to check
But how to use differently letters for disks
Two options:
1) Quick and dirty: start the multiple conversion before the first one finishes. The function will work.
2) Adit the script to keep an array of already used drive letter and exclude them from being used until a next reboot. That gives you the number of availbe drive letters /2 runs.
Thanks for your reply,
I tried to edit the script to present another drive letters
$script:TargetDriveLetterESP = “T” # Drive letter allocated to the ESP on the target disk
$script:TargetDriveLetterWindows = “L”
and i see new disks showed up in windows explorer but in stage applying image, the new letters disappeared and the script starting to show me error that the specified target disk is not found
Appreciate if you shared with me the latest script that you used after modifications
Thanks in advance
Was just an idea. Haven’t written it yet.