Home » PowerShell » Using PowerShell – IIS Get list of Websites

Using PowerShell – IIS Get list of Websites

The `Get-IISSite` cmdlet in PowerShell gets the IIS websites. You can specify the Name parameter to get IIS site information like the IIS website name, physical path, and bindings.

Get-IISSite

Internet Information Server (IIS) is a free, flexible, and Windows Operating System webserver to host websites and provides internet-based services.

The IIS server manages a list of websites and app pools. Most often system administrator manages IIS routine tasks to get a list of websites hosted on the IIS web server and get all IIS bindings and SSL certificates list. Using PowerShell, all these tasks can be easily automated.

Using the PowerShell Get-IISSite cmdlet, you can easily get a list of websites in IIS. The PowerShell IISAdministration module offers better support for the pipeline and contains many cmdlets to efficiently manage the IIS web server.

PowerShell - IIS Get List of Websites
PowerShell – IIS Get a List of Websites

In this article, I will explain to you how to get a list of websites hosted in IIS with step-by-step examples.

Prerequisites

  • IIS 10.0 Windows Features enabled and installed
  • PowerShell 5.1 or PowerShell 6+ version
  • IISAdministration module installed

Assuming, you have a minimum version of PowerShell and IIS10.0 Windows feature enabled.

Let’s start with the installation of the PowerShell IISAdministration module

Installation of IISAdministration module

Open the PowerShell console or PowerShell ISE with elevated ( run as administrator) mode and run the below command

PS C:\> Install-Module -Name 'IISAdministration'

The above command will install the IISAdministration module

Cool Tip: Do you know how to print environment variables in PowerShell!

PowerShell – IIS Get a List of Websites

Get-IISSite cmdlet in PowerShell gets iis websites and their key information.

Get a List of websites in the IIS Server

To get a list of websites hosted in the IIS server, run the following command.

PS C:\> Get-IISSite

Above the Get-IISSite command in PowerShell, get a list of websites hosted in the IIS web server.

The PowerShell Get-IISSite command also gets website details such as

  • Website name
  • Website Status
  • Website Physical Path
  • IIS bindings for Website
PoweShell - GetIISSites - website state, bindings
PowerShell – GetIISSites – website state, bindings

Use Get-ChildItem iis:sites to get all websites and applications

You can use the Get-ChildItem cmdlet in the PowerShell that uses the PSDrive iis:sites to retrieve all websites. This command requires the WebAdministration module to be imported before running the following command.

# Import the WebAdministation module
Import-Module WebAdministration

# Get the list of iis websites and applications
Get-ChildItem iis:sites 

The output of the above PowerShell script displays the list of websites configured in the IIS server.

PS C:\> Get-ChildItem iis:sites                                                                                         
Name             ID   State      Physical Path                  Bindings
----             --   -----      -------------                  --------
Default Web Site 1    Started    %SystemDrive%\inetpub\wwwroot  http *:80:
                                                                net.tcp 808:*
                                                                net.msmq localhost
                                                                msmq.formatname localhost
                                                                net.pipe *
HMI              2    Started    C:\inetpub\wwwroot\TEST HMI    http *:4001:
HMITest          3    Started    C:\inetpub\wwwroot\charity     http *:3500:
                                                                https *:443: sslFlags=0

Display information about the IIS website

To get information about a particular IIS website, use the Name parameter and provide the website name as a string.

PS C:\> Get-IISSite -Name 'TestHMI'

Name             ID   State      Physical Path                  Bindings                                     
----             --   -----      -------------                  --------                                     
TestHMI          2    Started    C:\inetpub\wwwroot\TEST HMI    http *:1001:                                 



PS C:\> 

In the above example, the PowerShell Get-IISSite command uses the Name parameter to specify the name of the website and get all configuration and key parameters like IIS website status, IIS website Physical Path, and IIS website bindings.

Cool Tip: Do you know how to enable psremoting for remote commands in PowerShell!

Conclusion

I hope you will find the above article about how to get a list of websites from IIS using PowerShell useful and educational.

Using the Get-IISSite cmdlet, you can easily query the IIS webserver to get a list of IIS websites and configuration details about websites like website name, IIS website status, IIS website Physical Path, and IIS website bindings information.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.