IISAdministration PowerShell Cmdlets (New feature in Windows 10 / Server 2016)
With Windows 10, IIS Team is releasing a new and simplified IISAdministration module side by side with the existing WebAdministration Cmdlets. There are many reasons behind the decision to release an entirely new PowerShell Cmdlet module and here are a few of them:
- IISAdministration will scale better in scripts that take a long time to run with WebAdministration.
- You can now get a direct reference to an instance of Microsoft.Web.Administration.ServerManager object and do anything that you can do in Microsoft.Web.Administration namespace alongside your scripts.
- PowerShell pipeline compatibility was the driving force behind the design of many cmdlets. As such, IISAdministration works much better with PowerShell Pipeline.
The version of the Cmdlets we are releasing in Windows 10 is a rough version with room for improvement. Our targeted release is for Windows Server 2016 for the finished and polished product. The reason we release this now is to get feedback from real PowerShell users and IIS Administrators in the industry, answer any questions and receive suggestions about not only the existing functionality but also potentially for new functionality our users would want from IIS Administration as it pertains to PowerShell.
Here, I will try to give some examples on the usage of the new provider:
Pipelining
PS:>Get-IISConfigSection -SectionPath "system.webServer/defaultDocument" | Get-IISConfigCollection -CollectionName "files" | New-IISConfigCollectionElement -ConfigAttribute @{"Value" = "MyDefDoc.htm"}
Get-IISConfigSection is at the beginning of most pipelines and in the specific example above, we are first getting the "system.webServer/defaultDocument" section (Case Sensitive!), then get the files collection, and finally get a collection element with the given attribute value.
PS:>$ConfigSection = Get-IISConfigSection -SectionPath "system.applicationHost/sites"
PS:>Get-IISConfigCollection $configSection | Get-IISConfigCollectionElement -ConfigAttribute @{"Name"="Default Web Site"} | Get-IISConfigAttributeValue -AttributeName "State"
This one is more of a hybrid example where the section is first put into a variable, then used in the pipeline.
Simple Commands
The number of simple commands are greatly reduced to a few. The examples include Get-IISSite and Get-IISAppPool. Other simple operations for which the commands do not exist can be performed through pipeline operations.
PS:> Get-IISAppPool
Name Status CLR Ver Pipeline Mode Start Mode
---- ------ ------- ------------- ----------
DefaultAppPool Started v4.0 Integrated OnDemand
Get-IISServerManager
PS:>$sm = Get-IISServerManager
PS:>$sm.ApplicationPools["DefaultAppPool"].Recycle()
As you can see, once you have access to the server manager, the sky is the limit.
Start-IISCommitDelay / Stop-IISCommitDelay
By enclosing your operations between these commands, you can make sure that your changes are committed at the same time.
These are only a handful of examples of what you can do with the new provider. Visit TechNet for the complete documentation and more examples.