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.
WebAdministration
IIS
Provides access to IIS configuration and run-time data.
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.
The following examples demonstrate how to use WebAdministration cmdlets to perform common IIS administration tasks.
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:\
The following example uses the Set-Location cmdlet to change the current location to the Sites folder.
Set-Location \Sites
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'
The following example uses the Get-Childitem cmdlet to display the existing Web sites in the Sites folder.
Get-ChildItem IIS:\Sites
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'
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'}
The following example uses the Get-ChildItem cmdlet to display IIS application pools.
Get-ChildItem IIS:\AppPools
The following examples demonstrate how to use cmdlets to create new Web sites, application pools, Web applications, and virtual directories.
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
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.
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
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.
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
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
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
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"}
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"}
The following example uses the Clear-ItemProperty cmdlet to remove all bindings from an existing Web site.
Clear-ItemProperty IIS:\Sites\DemoSite -Name bindings
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"})
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"}
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 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.
Specifies the file system path for a Web site or application.
- New-Item
Specifies the bindings for a site.
- New-Item
Specifies the type of a new IIS item.
- New-Item