5

If I run the following command on my server:

%windir%\system32\inetsrv\AppCmd.exe list site

I get this output:

SITE "MyCompany.MyProject.WebRole_IN_0_Web" (id:1273337555,bindings:https/555.555.555.555:443:,state:Started)

How can I get just the site name:

MyCompany.MyProject.WebRole_IN_0_Web

Is some kind of nasty string parsing my only option? The server is a Windows Azure instance.

Tom Robinson
  • 775
  • 2
  • 11
  • 21
  • why you need that? You need to put that string in a text file or similar things? In this case, consider to use shell script to manipulate strings. – Nicola Boccardi Jan 11 '11 at 14:15
  • @Nicola Because it's created dynamically I can't hard-code it, so I need to get it as a variable that I can use in my batch file for some configuration I need to make. – Tom Robinson Jan 11 '11 at 14:36

2 Answers2

13

Got it:

appcmd list site /text:name

Gives you this:

MyCompany.MyProject.WebRole_IN_0_Web

The help describes how this works:

/text<:value>    Generate output in text format (default).
                 /text:* shows all object properties in detail view.
                 /text:<attribute> shows the value of the specified
                 attribute for each object.

I worked out that name was the correct attribute by calling:

appcmd list site /xml

Which returns in XML format (including attribute names):

<?xml version="1.0" encoding="UTF-8"?>
<appcmd>
    <SITE SITE.NAME="MyCompany.MyProject.WebRole_IN_0_Web" SITE.ID="1273337555" bindi
gs="https/555.555.555.555:443:" state="Started" />
</appcmd>
Tom Robinson
  • 775
  • 2
  • 11
  • 21
2

If you are looking to configure the site/application pool using an AppCmd startup task, check out my recent post about this:

http://mvolo.com/configure-iis-websites-windows-azure-startup-tasks-appcmd/

This covers how to find the site/application pool to edit, and also how to run the task AFTER the site/apppool configuration is created and not before.

Hope this helps.

ionwarp
  • 21
  • 2