Convert WindowsImage PS1 File

Revision as of 10:19, 25 January 2018 by Root (talk | contribs)

Convert-WindowsImage.ps1

First, the disclaimer. This article is not about a step by step of how to use this utility. Rather it is about the problems I ran into using this utility.

Problem #1; Error message and it won't run

Basically I typed the name of the file to run Convert-WindowsImage.ps1 and got a warning and remember immediately that I should have pre-pended .\ to the beginning of it.
.\Convert-WindowsImage.ps1

Problem #2; No error message after using the Set-Execution command and it still won't run

This issue was related to all of the restrictions and protections Microsoft puts in place to protect us from all the evil in the world and at the same time make the PowerShell completely dysfunctional (or so it seems). You've might have already read about and tried the Set-Execution Policy to Unrestricted or Bypass and still have nothing work as happened to me. The key to figuring this out was a simple comment by a contributor on a forum. He said, "...downloaded from the internet." That made me think about these warning dialogs in Windows 10 that would pop up when I opened videos, music files, graphics, or anything else downloaded from the internet that put up an extra warning alluding to the file being from the internet and asking if I really wanted to open the file.

I did download the Convert-WindowsImage.ps1 file from the internet, but wait, it's just a text file, why don't I just create a new text file on my computer and copy and paste the contents of the original file into the new one? So I did. And it worked as the new file I created wasn't downloaded from the internet, but whose origins were local on my computer.

Problem #3; Similar to #2 with no error message and it still won't run

Another tip from another contributor on some forum noted that the entire Convert-WindowsImage.ps1 file was written as a Function. Go ahead, open up the file in a text editor and even if you don't know anything about programming, you'll see that 'Function' delimiter right at the top. In layman's terms it means if you type .\Convert-WindowsImage.ps1, it won't work. Maybe it did in the past (prior to 2018) with other versions of this script or other version of Windows, which is why there are so many sites that instruct one to simply type .\Convert-WindowsImage.ps1 and you'll be on your merry way. But if you're trying this in 2018 or later and using the latest version of the script.

Can it get worse? YES!

OK! Great! I've got my VHDX file and I'm good to go, right? Of course not. After attaching the VHDX file to the Hyper-V VM, it wouldn't start because the VHDX file was still locked, even after terminating the script and checking Task Manager to see if the VHDX file was still in use. Nope, logging of and logging back on didn't work. Checked what process had the file locked using LockHunter (I'm not affiliated with this person or company, but it is really useful software so consider contributing to them) and it was locked by a process called System.

Tip

Don't ever end a process called System, especially if it has a PID (Process ID) of 4, which indicates it started fairly early in the Windows boot process and is probably important. Seems obvious. I learned this one about 20 or so years ago in the Windows NT 4 era.

Anyway

The End

And in the end it still didn't work. The origin of this story is that I was attempting to convert an ISO image into a VHDX file. I went through all of the above problems only to have it not work. Well, what should I expect, the ISO image wouldn't boot in a generation 2 Hyper-V machine, so why would that same ISO image converted into a VHDX file boot? It wouldn't. So I continued to hammer away at the problem.

And another tip from another contributor indicated that indeed the ISO was successfully booting, but was displaying the "Press any key to boot from CD or DVD..." so quickly there wasn't a chance to press a key, let alone see the message. This seemed credible to me as during booting, newer versions of Windows (8 plus I believe) no longer let one press the F8 key during boot to bring up the boot menu, that is unless one configures that to happen ahead of time, which if one is dealing with a crashed system isn't possible.

The Real End

The real end of the story is that even though Windows Server 2008 R2 is supported in Hyper-V on Server 2016, it is only supported as a Generation 1 machine, not a generation 2. I had read that Hyper-V on Server 2016 did support Windows Server 2008 R2. And it did. I didn't read the fine print about it requiring that W2K8R2 be configured as a Generation 1 machine.

I know, I know, even Vista and maybe XP as a 64 bit machine can boot as a UEFI machine. But it isn't about what is possible, it's about what Microsoft allows in their software. So if you don't like Pepsi, have a Coke, IE, ditch Hyper-V and head on over to VMWare. Keep in mind I still use Hyper-V on all of my servers, so I'm not actually recommending VMWare, I'm just pointing out there are other choices if Microsoft makes you unhappy.