Do complex IIS management tasks easily with AppCmd command piping

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.

Published 19 June 07 12:22 by Mike Volodarsky
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Mike Volodarsky's WebLog said on June 19, 2007 1:04 PM:

As much as I hate to re-post someone else's content, I've been real busy in the past few weeks and havent

# Mike Volodarsky's ServerSide said on October 6, 2007 2:05 AM:

IIS7 provides quite a few ways to create websites, applications, and application pools. The simplest

# ASP.NET Debugging said on April 1, 2008 9:38 AM:

So with IIS7, there is a new way to get data out about your web server, using the new appcmd.exe process.

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below


About Mike Volodarsky

For the past 5 years, I was the core Program Manager for Microsoft ASP.NET 2.0 and IIS 7.0 products. I drove the design and development of the IIS 7.0 web server core, the IIS FastCGI support, the AppCmd command line tool, the ASP.NET Integrated pipeline, and other special projects around server security, performance, and scalability. Now, I am working on my own on cutting edge web server tech on top of the Microsoft IIS platform, and continue blogging about it here.

About me



For the past 5 years, I was the core server Program Manager for the IIS 7.0 and ASP.NET 2.0 products at Microsoft.
Now, I work on advanced web server tech using IIS 7.0, .NET, and Windows Server 2008 and write about it in this blog.

View Michael Volodarsky's profile on LinkedIn

Writings



TechNet Magazine
>Top 10 Performance Improvements in IIS 7.0

MSDN Magazine
>IIS 7.0: Build Web Server Solutions with End-To-End Extensibility
>IIS 7.0: Enhance Your Apps with the Integrated ASP.NET Pipeline
>IIS 7.0: Explore The Web Server For Windows Vista And Beyond
>Design and Deploy Secure Web Apps with ASP.NET 2.0 and IIS 6.0
>Fast, Scalable, and Secure Session State Management for Your Web Applications


Tools and Modules

LeechGuard
IconHandler 2.0
DirectoryListing
HttpRedirection
IIS Auth for Wordpress
iisschema.exe
PortCheck.exe v2.0

Popular Posts

- ASP.NET 2.0 Breaking Changes on IIS 7.0
- Develop IIS7 modules and handlers with .NET
- Troubleshoot IIS7 errors like a pro
- Troubleshooting 503 / "service unavailable" errors
- Troubleshooting "server not found" errors
- Create IIS7 sites, applications, and virtual directories
- Run Ruby on Rails with IIS FastCGI
- VS Debugging of ASP.NET applications on Windows Vista
- Stop hot-linking with IIS and ASP.NET

Tags

Search

Go

This Blog

Archives

Good IIS Blogs

Disclaimer

These postings are provided as is with no warranties, and confer no rights. The views expressed in this blog are entirely my own.

Syndication