Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS: Display all sites and bindings in PowerShell

I am documenting all the sites and binding related to the site from the IIS. Is there an easy way to get this list through a PowerShell script rather than manually typing looking at IIS?

I want the output to be something like this:

Site                          Bindings TestSite                     www.hello.com                              www.test.com JonDoeSite                   www.johndoe.site 
like image 732
sanjeev40084 Avatar asked Mar 20 '13 15:03

sanjeev40084


People also ask

How do I get a list of IIS sites?

The Get-IISSite cmdlet gets information about Internet Information Services (IIS) web sites and their current status and other key information. If you a request a specific site or a comma delimited list of sites, only those whose names are passed as an argument are returned.

How do you check if IIS is running using PowerShell?

5] Using Windows Powershell First, open Windows Powershell by searching for Powershell in the Cortana search box and run it with Administrator level privileges. It will look similar to this, Hence, you will find the version of IIS installed on your computer using Windows PowerShell. Hope this helps!


2 Answers

Try this:

Import-Module Webadministration Get-ChildItem -Path IIS:\Sites 

It should return something that looks like this:

Name             ID   State      Physical Path                  Bindings ----             --   -----      -------------                  -------- ChristophersWeb 22   Started    C:\temp             http *:8080:ChristophersWebsite.ChDom.com 

From here you can refine results, but be careful. A pipe to the select statement will not give you what you need. Based on your requirements I would build a custom object or hashtable.

like image 152
Christopher Douglas Avatar answered Sep 19 '22 18:09

Christopher Douglas


Try something like this to get the format you wanted:

Get-WebBinding | % {     $name = $_.ItemXPath -replace '(?:.*?)name=''([^'']*)(?:.*)', '$1'     New-Object psobject -Property @{         Name = $name         Binding = $_.bindinginformation.Split(":")[-1]     } } | Group-Object -Property Name |  Format-Table Name, @{n="Bindings";e={$_.Group.Binding -join "`n"}} -Wrap 
like image 40
Frode F. Avatar answered Sep 19 '22 18:09

Frode F.