As much as I hate to re-post someone else's content, I've been real busy in the past few weeks and havent had a chance to post new stuff - and today I saw Kanwal's post on a very near and dear subject of mine: AppCmd command pipelining.

Things you can do by piping appcmd commands

The post covers command pipelining, the advanced AppCmd feature that enables complicated management tasks to be expressed simply by combining multiple related appcmd commands, that operate on a pipeline of results generated by prevous commands.

For example:

AppCmd list apppools /state:Stopped finds the application pools that are stopped.

AppCmd start apppool XYZ starts the specified apppool.

What if you wanted to find the stopped apppools, and start them?  You could write a script, with a FOR loop, etc - or you can use AppCmd piping to do it like a pro:

AppCmd list apppools /state:Stopped /XML | AppCmd stop apppools /in

The /XML switch in the first command outputs the result of the first command in XML, and the /IN switch of the second command allows the list of apppools to stop to come in from STDIN.

This can be applied as many times as you want with most AppCmd commands.  Since appcmd allows you to query for objects with any of its properties, you can turn it the command piping ability into a very powerful way to do complex tasks - for example:

appcmd list sites /state:started /traceFailedRequestsLogging.enabled:true /XML |
     appcmd list apps /IN /XML |
        appcmd list apppools /IN /XML | 
            appcmd recycle apppools /IN

This finds all sites that are started and have Failed Request Tracing enabled, finds their applications, then finds the apppools to which they belong, and recycles them.

Before you ask - I designed and implemented this feature before I was exposed to Powershell, and was happy to see that Powershell supports this generically for most of its commands.  If I had known that ahead of time, I may have never implemented the support in AppCmd ... but as history would have it, I did, and now you get to take advantage of this capability in IIS7, without Powershell installed or the requirement to write your own powershell commandlets.

Read Kanwal's article for more examples of commands - I'll be sure to post my favorite ones, and some cool tricks using pipelining, in the near future.