Web Administration (IIS) Provider for Windows PowerShell

Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista

This topic describes the Web Administration (IIS) provider for Windows PowerShell.

Provider Name

WebAdministration

Drives

IIS

Short Description

Provides access to IIS configuration and run-time data.

Detailed Description

The WebAdministration provider for Windows PowerShell lets you manage the configuration and run-time data of Internet Information Services (IIS). It implements a namespace hierarchy that contains application pools, Web sites, Web applications, and virtual directories.

The provider implements one virtual drive named IIS. The root virtual folders are AppPools and Sites.

Run-time data, such as the currently running WorkerProcesses, AppDomains, and Requests can be found in the AppPools folder.

The Sites folder contains Web site folders, in addition to applications and virtual directories.

Example cmdlets to perform common IIS Administration tasks

The following examples demonstrate how to use WebAdministration cmdlets to perform common IIS administration tasks.

Display the contents of the IIS drive by using the Get-ChildItem cmdlet

The following example uses the Get-Childitem cmdlet to display contents of the IIS root drive. If the current drive is IIS:\ you can omit the path.

Get-ChildItem -Path IIS:\

Change the location to a folder by using the Set-Location cmdlet

The following example uses the Set-Location cmdlet to change the current location to the Sites folder.

Set-Location \Sites

Change the location to a site by using the Set-Location cmdlet

The following example uses the Set-Location cmdlet to change the current location to the Sites\Default Web Site folder. If the path contains spaces, you must enclose it in single quotation marks.

Set-Location '\Sites\Default Web Site'

Display the sites in the Sites folder by using the Get-ChildItem cmdlet

The following example uses the Get-Childitem cmdlet to display the existing Web sites in the Sites folder.

Get-ChildItem IIS:\Sites

Display items in the Default Web Site by using the Get-ChildItem cmdlet

The following example uses the Get-Childitem cmdlet to display items in the Default Web Site. If the path contains spaces, you must enclose it in single quotation marks.

Get-ChildItem 'IIS:\Sites\Default Web Site'

Display applications in the Default Web Site by using the Get-ChildItem cmdlet

The following example uses the Get-ChildItem cmdlet with a where argument that constrains the output to applications only. You can display only virtual directories by replacing ‘Application’ with ‘Virtual Directory’.

Get-Childitem 'IIS:\Sites\Default Web Site' | where {$_.Schema.Name -eq 'Application'}

Display IIS application pools by using the Get-ChildItem cmdlet

The following example uses the Get-ChildItem cmdlet to display IIS application pools.

Get-ChildItem IIS:\AppPools

Example cmdlets to create Web sites, application pools, Web applications, and virtual directories

The following examples demonstrate how to use cmdlets to create new Web sites, application pools, Web applications, and virtual directories.

Create a new Web Site by using the New-Item cmdlet

The following example uses the New-Item cmdlet to create a new Web site named DemoSite. The site is configured to listen on port 8080, and the physical path to the folder containing the site is specified by the PhysicalPath parameter. The folder specified for the site, C:\inetpub\DemoSite, must be created before you execute the cmdlet.

New-Item IIS:\Sites\DemoSite -bindings @{protocol='http';bindingInformation=':8080:DemoSite'} -PhysicalPath C:\inetpub\DemoSite

Create a new application pool by using the New-Item cmdlet

The following example uses the New-Item cmdlet to create a new application pool named DemoPool.

New-Item IIS:\AppPools\DemoPool

The following example uses the Set-ItemProperty cmdlet to assign a site or an application to application pools.

Create a new Web application in the Default Web Site by using the New-Item cmdlet

The following example uses New-Item cmdlet to create a new Web application that runs in the Default Web Site. The folder specified for the application, C:\inetpub\DemoApplication, must be created before you execute the cmdlet.

New-Item 'IIS:\Sites\Default Web Site\DemoApplication' -Type Application -PhysicalPath C:\inetpub\DemoApplication

Create a new virtual directory by using the New-Item cmdlet

The following example uses the New-Item cmdlet to create a new virtual directory in the Default Web Site. The folder specified for the virtual directory, C:\inetpub\DemoVirtualDirectory, must be created before you execute the cmdlet.

New-Item 'IIS:\Sites\Default Web Site\DemoVirtualDirectory' -Type VirtualDirectory -PhysicalPath C:\inetpub\DemoVirtualDirectory

Example cmdlets that change the properties of a site, application pool, application, or virtual directory

The following examples demonstrate how to use cmdlets to change, add, or remove properties for Web sites, application pools, Web applications, and virtual directories.

Set the application pool for an example by using the Set-ItemProperty cmdlet

The following example uses the Set-ItemProperty cmdlet to set the ApplicationPool property of an application.

Set-ItemProperty 'IIS:\sites\Default Web Site\DemoApplication' -Name applicationPool -Value DemoPool

Set the request limit to recycle an application pool by using the Set-ItemProperty cmdlet

The following example uses the Set-ItemProperty to set the request limit to recycle the application pool to 100000.

Set-ItemProperty 'IIS:\AppPools\DemoPool' -Name recycling.periodicRestart.requests -Value 100000

Change the physical path of a virtual directory by using the Set-ItemProperty cmdlet

The following example uses the Set-ItemProperty cmdlet to change the physical path of a virtual directory.

Set-ItemProperty 'IIS:\Sites\Default Web Site\DemoVirtualDirectory' -Name physicalPath -Value C:\inetpub\newDemoVirtualDirectory

Change the binding of a site by using the Set-ItemProperty cmdlet

The following example uses the Set-ItemProperty cmdlet to change the binding of a site.

Set-ItemProperty IIS:\Sites\DemoSite -Name bindings -Value @{protocol="http";bindingInformation="*:80:ChangedDemoSiteBinding"}

Add a binding to an existing Web site by using the New-ItemProperty cmdlet

The following example uses New-ItemProperty cmdlet to add a new binding to an existing Web site.

New-ItemProperty IIS:\Sites\DemoSite -name bindings -value @{protocol="http";bindingInformation="*:80:NewDemoSiteBinding"}

Remove all bindings from a Web site by using the Clear-ItemProperty cmdlet

The following example uses the Clear-ItemProperty cmdlet to remove all bindings from an existing Web site.

Clear-ItemProperty IIS:\Sites\DemoSite -Name bindings

Replace existing bindings with new bindings by using the Set-ItemProperty cmdlet

The following example uses the Set-ItemProperty cmdlet to replace existing bindings with a set of new bindings. An array of hash tables is used to achieve this.

Set-ItemProperty IIS:\Sites\DemoSite -Name bindings -Value (@{protocol="http";bindingInformation="*:80:DemoSite1"},@{protocol="http";bindingInformation="*:80:DemoSite2"})

Remove a binding from the <bindings> collection by using the Remove-ItemProperty cmdlet

The following example uses the Remove-ItemProperty cmdlet to remove an existing binding from the <bindings> collection.

Remove-ItemProperty 'IIS:\Sites\DemoSite' -Name bindings -AtElement @{protocol="http";bindingInformation="*:80:DemoSite2"}

Rename an IIS configuration object by using the Rename-Item cmdlet

The following example uses the Rename-Item cmdlet to rename an existing IIS configuration object. The site to rename must exist before you execute the cmdlet.

Rename-Item IIS:\Sites\DemoSite DemoSite2

DYNAMIC PARAMETERS

Dynamic parameters are cmdlet parameters that are added by a Windows PowerShell provider and are available only when the cmdlet is being used in the provider-enabled drive.

PhysicalPath &lt;System.Management.Automation.SwitchParameter&gt;

Specifies the file system path for a Web site or application.

Cmdlets supported:

  • New-Item

Bindings &lt;System.Management.Automation.SwitchParameter&gt;

Specifies the bindings for a site.

Cmdlets supported

  • New-Item

Type &lt;Application, VirtualDirectory&gt;

Specifies the type of a new IIS item.

Cmdlets supported

  • New-Item

See Also

Other Resources

Web Administration (IIS) cmdlets