MSDeploy , XPath and XSL: Part 1: Getting information

Posted: Sep 25, 2009  2 comments  

Average Rating

Share this Post

 

Now that MSDeploy RTW has been officially released, I want to discuss just some of the few great features it has.

Getting Information:

The tool can be used in great many ways to get remote or local system information using xpath with the different providers. A few of the scenarios are given below:

1. General Rule:

One general rule before we start is that, since XPath is case sensitive you can make it case insensitive in a way by using the translate function and changing the case of all the values to lower case and carrying out a lower case comparison. For e.g. if you are looking for all sites that start with “Default” and don’t care if its “Default” or “default” you can use this command as follows:

msdeploy -verb:dump -source:apphostconfig -xml -disableLink:content -xpath=//*[contains(translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'default web')]

This command tells xpath compiler to convert the value of @name attribute to lower case before verifying whether this value contains ‘default web’. This can be used for all examples below.

2. Find if .net 3.5 is installed on a remote system:

msdeploy -verb:dump -source:regKey="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP",tempAgent=true,computername=someserver -xml -xpath=//*[@path='v3.5']

If the remoteserver does have .net 3.5 installed you will see an output as:

<output>
  <regKey path="v3.5" securityDescriptor="D:">
    <regKey path="1033" securityDescriptor="D:">
      <regValue name="Version" valueType="String" value="3.5.30729.4926" />
      <regValue name="CBS" valueType="DWord" value="1" />
      <regValue name="Install" valueType="DWord" value="1" />
      <regValue name="SP" valueType="DWord" value="1" />
    </regKey>
    <regValue name="Version" valueType="String" value="3.5.30729.4926" />
    <regValue name="CBS" valueType="DWord" value="1" />
    <regValue name="Install" valueType="DWord" value="1" />
    <regValue name="InstallPath" valueType="String" value="C:\Windows\Microsoft.NET\Framework\v3.5\" />
    <regValue name="SP" valueType="DWord" value="1" />
  </regKey>
</output>

3. Find all files that were modified on a specific date on a remote target or have a specific size:

msdeploy –verb:dump –source:dirPath=c:\inetpub\wwwroot,computername=remoteserver,tempAgent=true -xpath=//*[@path='content']/*[contains(@lastWriteTime,'7/01/2009')]

This will give you all the files under the content folder that have been last modified on 7/1/2009. You can alternatively change xpath to //*[contains(@lastWriteTime,'7/01/2009')] to get all files under inetpub\wwwroot instead of just the files in content folder underneath this.

4. Find all applications that use “mycoolAppPool”:

msdeploy.exe -verb:dump -source:apphostconfig -disableLink:Content -xml -xpath=//*[@applicationPool='mycoolapppool']

5. Find out if more than 1 application has been set to use the port 8080:

msdeploy.exe -verb:dump -source:apphostconfig -disableLink:Content -xml -xpath=//*[contains(@bindingInformation,'8080')]

6. Find all the different host headers that your sites are using on port 80:

msdeploy.exe -verb:dump -source:apphostconfig -disableLink:Content -xml -xpath=//*[contains(@bindingInformation,'80’)]

7. Find all sites that do not have any apps or vdirs beneath them:

msdeploy.exe -verb:dump -source:apphostconfig -disableLink:Content -xml -xpath=//site[count(application)=1]

8. Find all directories that are empty

msdeploy.exe –verb:dump –source:dirPath=C:\inetpub\wwwroot,computername=remoteserver –xml -xpath=//dirPath[not(*)]

Comments

could you please provide database scripts

Oct 18 2012 by amar.pandharpure

Why isn't all this done in PowerShell. Why is it all some new arcane syntax? I won't use it and neither will anyone else.

Dec 13 2012 by myscreennamewastaken

Submit a Comment

  • Plain text is accepted.
  • URLs starting with http:// are converted to links.