skip to Main Content

Running MSDEPLOY from PowerShell

I had to spend quite a bit of time figuring this out. So hopefully this will help someone out there. To launch MSDEPLOY from PowerShell, make sure you escape any quote or comma characters.

The “2>&1” at the end allows Powershell to detect errors and bail out if you have $ErrorActionPreference = “Stop”

If you still have problems, download and use EchoArgs.exe to see exactly what PowerShell sees.

Example

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

  if (!(Test-Path "$path")) {
    throw "MSDEPLOY.EXE is not installed. See http://go.microsoft.com/?linkid=9278654"
  }

  return $path
}

$msdeploy = Get-MSWebDeployInstallPath

& $msDeploy -verb:sync -source:recycleApp `
  -dest:recycleApp=`"${webSiteName}`"`,recycleMode=StopAppPool`,wmsvc=${server}`,userName="${userName}"`,password="${password}" `
  -allowuntrusted -debug 2>&1

Error 1053 starting Web Deployment Agent Service

If you are getting error 1053 starting “Web Deployment Agent Service” (part of Microsoft Web Deploy or MSDEPLOY), below is a possible fix.

This is the error I got when trying to start Web Deployment Agent Service: “Web Deployment Agent Service” on some of my servers. The exact error message is: “Windows could not start the Web Deployment Agent Service service on Local Computer. Error 1053: The service did not respond to the start or control request in a timely fashion.”

In the System Events Log, there are these generic service start-up error messages:

  • The Web Deployment Agent Service service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion.”
  • A timeout was reached (30000 milliseconds) while waiting for the Web Deployment Agent Service service to connect.

The fix for me was to uninstall any previous version of Web Deploy, then re-install the latest version (Microsoft Web Deploy 3.5), and choosing “Complete” at the “Choose Setup Type” page.

My environment: Windows Server 2008 64-bit SP2.

Replacement straws for Thermos Bottles

Sorry this has nothing to do with coding.

But if you have kids and have the Thermos aluminum straw Bottles such as the Thermos Funtainer or Foogo Straw bottles, you can get replacement straws directly from Thermos for $1 a piece. My kids like to bite the straws and they get destroyed pretty quickly. If you need just the top part of the straw, that would be $0.50.

imageThermos Funtainers Disney Cars sip bottle

Apparently, people are reselling these straws on Ebay and other sites for $7-$10 a piece! So Thermos is limiting each order to 5 straws. I am putting this out there to hopefully direct people to the source.

Call Thermos directly at 1-800-831-9242 to order your replacement straws. If outside the US, try 1-847-439-7821.

Removing Excess Whitespace from a String

I was looking for the most efficient way to remove excess white space from a string and wrote the following benchmark. Guess which algorithm is faster?

const int iterations = 200000;
const string expr = " Hello    world! Why    are so    many spaces?  Testing One   two three    four    five.";

// Remove excess space using Regex
var doRegex = new Action(() =>
{
    for (int i = 0; i < iterations; i++)
    {
        var newStr = Regex.Replace(expr, @"\s{2,}", " ");
    }
});


// Remove excess space using Split/Join
var doSplit = new Action(() =>
{
    for (int i = 0; i < iterations; i++)
    {
        var newStr = String.Join(" ", expr.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
    }
});

var benchMark = new Func<string, Action, long>((name, a) => {
    var sw = Stopwatch.StartNew();
    a();
    sw.Stop();
    Console.WriteLine(name + ": " + sw.ElapsedMilliseconds);
    return sw.ElapsedMilliseconds;
});

// Warming up
Console.WriteLine("Warming up.");
doRegex();
doSplit();

// Run benchmark
long regexElapsed = benchMark("Regex", doRegex);
long splitElapsed = benchMark("Split", doSplit);

On my PC, the Split method is about 7.5 times faster than Regex.

image
Back To Top