user2986735
user2986735

Reputation: 11

Get a list of all websites in IIS7?

I wonder if anyone has got a Powershell script to share.

What I want is a script that will export all websites from IIS7 to a CSV file with the following values:

Name, URL, Port

Example:

Testapp, www.testapp.com, 80

I tried to export using Get-Website but when exporting to CSV I get only the name and the rest outputs like this Microsoft.IIs.PowerShell.Framework.ConfigurationElement

Humble regards,
Tobbe

Upvotes: 1

Views: 2591

Answers (1)

arco444
arco444

Reputation: 22831

Something like this should do the trick:

Import-Module webAdministration # Required for Powershell v2 or lower  

$filepath = #your_output_filepath
$sites = get-website

foreach($site in $sites) {
    $name = $site.name
    $bindings = $site.bindings.collection.bindinginformation.split(":")
    $ip = $bindings[0]
    $port = $bindings[1]
    $hostHeader = $bindings[2]
    "$name,$hostHeader,$ip,$port" | out-host
    "$name,$hostHeader,$ip,$port" | out-file $filePath -Append
}

Have included the site binding address in this too, omit the $ip variable from the outputs if you don't need it.

Upvotes: 2

Related Questions