Does anyone have a PowerShell Script to list IIS websites from an external server ?

Hi Everyone,

I have a Windows 2012 R2 server, and I need to audit the number of IIS websites we have across the server estate.  Does anyone have a PowerShell script that will audit for IIS website that are hosted on Windwos 2003 servers upwards ?

Appreciate anyones help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy LidbetterCommented:
Hi CaussyR,

Do you have the web servers in a specific OU or would you just like to search each and every box?


CaussyRAuthor Commented:
I would like to scan the whole server exstate, but as a starter AD would be fine.
CaussyRAuthor Commented:
In the time of asking this question, I have put to gether the following :

$Servers = get-content 'c:\temp\ServerList.txt'

try {
        foreach ($Hostname in $Servers)
            Write-Output $Hostname
            Get-WmiObject -Authentication PacketPrivacy -Impersonation Impersonate -ComputerName $Hostname -namespace "root/MicrosoftIISv2" -class IIsApplicationPool | `
            Select-Object -property @{N="Name";E={$name = $_.Name; $name.Split("/")[2] }} | Format-Table
    } Catch{

        Write-Output $Hostname + "Does not have IIS"

I get the Web App pools but not sure which WMI object to use to list the web site name.
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Guy LidbetterCommented:
Keep in mind the MicrosoftIISv2 root namespace will only work with II7 or IIS6 after you install the WMI Compatibility features. If you have not done this it won't work on your 2003 boxes unless you've updated to IIS of course...

You can use this to list the classes in the namespace.

Get-WmiObject -Namespace root\microsoftiisv2 -list
Guy LidbetterCommented:
By the way, instead of using a server list, install ad tools and run this to get all the servers

Import-Module ActiveDirectory
$Servers = Get-ADComputer -Filter * -Properties OperatingSystem |`
      Where {$_.OperatingSystem -like "*Server*"} | Select Name

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Guy LidbetterCommented:
Does this get the list of site you're looking for?

gwmi -Namespace "root/MicrosoftIISv2" -Query "SELECT * FROM IIsWebVirtualDirSetting" | select name,path,AppFriendlyName
CaussyRAuthor Commented:
Hi Guy,

Thank you for your assistance.

gwmi -Namespace "root/MicrosoftIISv2" -Query "SELECT * FROM IIsWebVirtualDirSetting" | select name,path,AppFriendlyName

Gave me a list of the following :

name                                        path                                                                   AppFriendlyName
----                                             ----                                                                       -------------
W3SVC/1/ROOT                      c:\inetpub\wwwroot                                       Default Application
W3SVC/19/Root                     e:\Projects\InformationHubPac...                  Default Application
W3SVC/20/Root                     e:\Projects\InformationHubPac...                  Default Application

So, it didn't return the actual name of the site but only the site number.  Do you have anything that would return the Site name rather than the Site ID ?
Guy LidbetterCommented:
It looks like the websites are running under the default site name... let me see if I can pull the Hostheaders\bindings...
CaussyRAuthor Commented:
Hi Guy, they are not runnint under the Default web site as virtual directories.  They are separate sites. hope this helps.
Greg HejlPrincipal ConsultantCommented:
I think appcmd.exe is what you are looking for here

Or a simple dir commeand should get your list for you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.