Getting the msdeploy.exe install path using powershell

by Naeem Khedarun 17. October 2011 08:00

 

I’ve been playing around with msdeploy and powershell lately, and one of the things I needed to find out is where the msdeploy.exe was located. After building a web deploy package, the associated batch file created by msdeploy uses a registry key to get the executables location.

Accessing the registry in powershell is super easy, so we may as well do the same thing. The key in question is: "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" which we can access using a standard Get-ChildItem or gci for short.

image

I have both MSDeploy v1 and v2 installed, and it’s the latter one I want to get at so we can use a Select –Last 1 to choose it. We also want just the InstallPath property which is accessible via GetValue on the RegistryKey object.

image

Great! We can easily put this into a function and load it into our path using:

function Get-MSWebDeployInstallPath(){
     return (get-childitem "HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" | Select -last 1).GetValue("InstallPath")
}

function Load-Configuration
{
    $webDeploy = Get-MSWebDeployInstallPath
    $env:Path += (";" + $webDeploy)
}

You should be able to access msdeploy from your powershell script now…

Categories: PowerShell | msdeploy

Fully automated VHD install of Windows 8 Developer Preview using PowerShell

by Naeem Khedarun 15. September 2011 08:47

 

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:

image

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

Usage

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:

image

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.

Categories: PowerShell

Accessing BCDBoot.exe from PowerShell

by Naeem Khedarun 15. September 2011 04:53

 

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:

C:\Windows\sysnative\bcdboot

image

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

Categories: PowerShell

Clearing all bin and obj folders using SlightlyPosher and PowerShell

by Naeem Khedarun 24. July 2011 18:38

 

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.

Clear-Assemblies

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

image

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.