Fully automated VHD install of Windows 8 Developer Preview using PowerShell


After reading Scotts excellent post: http://www.hanselman.com/blog/GuideToInstallingAndBootingWindows8DeveloperPreviewOffAVHDVirtualHardDisk.aspx

…and subsequently noticing a smart chap saying something about an easier way in the comments:


I decided to go ahead and make this even easier since PowerShell is my new hammer I’m going to take advantage of it. The Creating a Bootable VHD guide does specify that there is a Microsoft PowerShell script which makes this easier, so there is method to my madness.

The relevant code has already been pushed to Github: https://github.com/naeemkhedarun/CreateWindows8VHD

A direct download of the zip is: https://github.com/naeemkhedarun/CreateWindows8VHD/zipball/master


You need to download and mount the ISO yourself. You can get it from here and I recommend Virtual Clone Drive as a free and lightweight mounting tool.

The script has three parameters:

  1. Full path and name of the VHD you would like to create.
  2. The maximum size of the image.
  3. The drive letter to assign the VDH to (must not be in use).

An example of using it is:

cd C:\projects\CreateWindows8VHD
C:\projects\CreateWindows8VHD> Import-Module .\Create-Windows8VHD.ps1
C:\projects\CreateWindows8VHD> Create-Windows8VHD "C:\vhd\windows8preview.vhd" "30000" "X"

Here’s an example of my output:


Following this to set up a dual boot record you can do (where driveletter is what you choose above).

C:\Windows\sysnative\bcdboot.exe driveletter:\Windows

You should now be able to restart into the Windows 8 Preview!

Feel free to submit pull requests and make suggestions.

Accessing BCDBoot.exe from PowerShell


This one was driving me crazy for a little while…

The term 'bcdboot' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:8
+ bcdboot <<<<
    + CategoryInfo          : ObjectNotFound: (bcdboot:String) [], CommandNotFoundException

I wondered whether it was the case with all System32 binaries and security, so some Googling turned up: http://social.technet.microsoft.com/Forums/en-GB/configmgradminconsole/thread/f1662e6e-5b15-450a-bca1-f3e2f99b7580

So if you would like to access bcdboot from PowerShell, and for my current script I definitely do, then you can use:



Irritating, but a relief to find its possible. Happy hacking.

Clearing all bin and obj folders using SlightlyPosher and PowerShell


Sometimes an msbuild.exe /t:Clear doesn’t remove everything and it can be a little slow on larger solutions. Within the SlightlyPosher environment you’ll find a Module called VS.psm1, and this contains a handy little script when you need to do some house keeping.

function Clear-Assemblies($directory)
    Get-ChildItem $directory -include bin,obj -Recurse | foreach ($_) { 
        "Cleaning: " + $_.fullname
        remove-item $_.fullname -Force -Recurse 


It’s pretty simply and to the point, just navigate to the root directory of the solution you want to clear down, and run this command.


It will recursively remove all bin and obj folders, and let you know what it deleted.


Great for when you need to copy source code without the added bulk of these folders or just purge any old bits for a clean build.

SlightlyPosher now supports 64bit PowerShell


When trying to write some scripts to automate IIS, I was getting some strange COM errors which were down to trying to run cmdlets targeted at a 64bit process.

It turns out Console2 as a 32bit process can only host a 32bit command prompt, which is unfortunate. Luckily Console2 does have a beta 64bit version, and I’m shipping this side by side with the 32bit version to satisfy everyone.

When you run update.bat you will find a new folder in your root.


Running [intptr]::size against the original shell yields:


And running it against the new shell:


I can now automate my 64bit IIS without errors. If everything is running fine you won’t need the new shell, but at least its there for the day you do need it.

Newer Posts Older Posts