powershell: list of sites in IIS

Getting a list of all the sites in IIS 6 is typically as easy as right-clicking Web Sites and choosing Export List. I decided I wanted to do this through PowerShell. I’m sure there are plenty of ways to do this, but this is one I got to use today.

$objSites = [adsi]”IIS://serverorlocalhost/W3SVC”
foreach ($objChild in $objSites.Psbase.children)
{ $objChild.servercomment }

This should output all the names of the sites that you would see in the IIS management console. If you want to know what else can be pulled, grab one of those objects and pipe it to get-member. I haven’t figured out how to pull the Home Directory, but IP should be under .ServerBindings, the ID should be under .Name, and so on. I suspect IIS7 will be even easier to manage via PowerShell.