Link to home
Start Free TrialLog in
Avatar of CaussyR
CaussyR

asked on

List Website Details from a Windows 2003 R2 Server ?

I am currently in the process of auditing the Windows 2003 servers running PS 2.0.  I have written the script below and run it from Powershell 4 on a Windows 2012 R2 server.  Does any one know how I cna modify it so it can also grab the IIS site details from a Windwos 2003 server ? The script works on a 2012 server.

        Import-Module WebAdministration
        Get-WebApplication
        # $webapps = Get-WebApplication
        $Servers = Get-Content 'c:\temp\ServerList.txt'
        $webapps = Get-WebSite
        $list = @()
   
   Foreach ($Hostname in $Servers)
   {
    try{
        foreach ($webapp in get-childitem IIS:\Sites\)
        {
            $name = "IIS:\Sites\"
            $item.Hostname = $Hostname
            $item.Name = $webapp.name
            $item.State = (Get-Website -Name $webapp.name).State
            $item.PhysicalPath = (Get-Website -Name $webapp.name).PhysicalPath
            $obj = New-Object PSObject -Property $item
            $list += $obj
        }

        $list | Format-Table -a -Property "Hostname","Name", "State", "PhysicalPath"

        }catch
        {
            $ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace
            $ExceptionMessage
        }
    }
ASKER CERTIFIED SOLUTION
Avatar of Nadav Solomon
Nadav Solomon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nadav Solomon
Nadav Solomon

Glad I could help, thanks for the feedback.