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.
CaussyRAsked:
Who is Participating?
 
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
0
 
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?

Regards

Guy
0
 
CaussyRAuthor Commented:
I would like to scan the whole server exstate, but as a starter AD would be fine.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
CaussyRAuthor Commented:
In the time of asking this question, I have put to gether the following :

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

cls
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.
0
 
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
0
 
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
0
 
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 ?
0
 
Guy LidbetterCommented:
It looks like the websites are running under the default site name... let me see if I can pull the Hostheaders\bindings...
0
 
CaussyRAuthor Commented:
Hi Guy, they are not runnint under the Default web site as virtual directories.  They are separate sites. hope this helps.
0
 
Greg HejlPrincipal ConsultantCommented:
I think appcmd.exe is what you are looking for here

https://technet.microsoft.com/en-us/library/jj635852.aspx

Or a simple dir commeand should get your list for you

http://www.iis.net/learn/manage/powershell/powershell-snap-in-navigating-the-iis-snap-in-namespace
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.