8

The goal is to automate enabling of IIS on a new Windows Workstation, like Windows 10, for a .NET development environment. I realize that Powershell scripts can be written to do something like this but I don't know where to start.

I realize I could easily go into Control Panel and enable the service there however it seems more efficient to just run a script to do this.

What would an example script look like that would be run in Powershell to enable IIS?

7

2 Answers 2

17

Server OS's

On Windows Server you could run the following command to automate installation of IIS:

#-LogPath can be added if you want a log to be created of the installation
#-Restart can be added if you want to auto restart after installation
Install-WindowsFeature -ComputerName SomePCHere -Name Web-Server

Here are the names of the IIS features from PowerShell's point of view:

Display Name                                            Name                 
------------                                            ----                      
    [ ] Web Application Proxy                           Web-Application-Proxy          
[ ] Web Server (IIS)                                    Web-Server                     
    [ ] Web Server                                      Web-WebServer                  
        [ ] Common HTTP Features                        Web-Common-Http                
            [ ] Default Document                        Web-Default-Doc                
            [ ] Directory Browsing                      Web-Dir-Browsing               
            [ ] HTTP Errors                             Web-Http-Errors                
            [ ] Static Content                          Web-Static-Content             
            [ ] HTTP Redirection                        Web-Http-Redirect              
            [ ] WebDAV Publishing                       Web-DAV-Publishing             
        [ ] Health and Diagnostics                      Web-Health                     
            [ ] HTTP Logging                            Web-Http-Logging               
            [ ] Custom Logging                          Web-Custom-Logging             
            [ ] Logging Tools                           Web-Log-Libraries              
            [ ] ODBC Logging                            Web-ODBC-Logging               
            [ ] Request Monitor                         Web-Request-Monitor            
            [ ] Tracing                                 Web-Http-Tracing               
        [ ] Performance                                 Web-Performance                
            [ ] Static Content Compression              Web-Stat-Compression           
            [ ] Dynamic Content Compression             Web-Dyn-Compression            
        [ ] Security                                    Web-Security                   
            [ ] Request Filtering                       Web-Filtering                  
            [ ] Basic Authentication                    Web-Basic-Auth                 
            [ ] Centralized SSL Certificate Support     Web-CertProvider               
            [ ] Client Certificate Mapping Authentic... Web-Client-Auth                
            [ ] Digest Authentication                   Web-Digest-Auth                
            [ ] IIS Client Certificate Mapping Authe... Web-Cert-Auth                  
            [ ] IP and Domain Restrictions              Web-IP-Security                
            [ ] URL Authorization                       Web-Url-Auth                   
            [ ] Windows Authentication                  Web-Windows-Auth               
        [ ] Application Development                     Web-App-Dev                    
            [ ] .NET Extensibility 3.5                  Web-Net-Ext                    
            [ ] .NET Extensibility 4.5                  Web-Net-Ext45                  
            [ ] Application Initialization              Web-AppInit                    
            [ ] ASP                                     Web-ASP                        
            [ ] ASP.NET 3.5                             Web-Asp-Net                    
            [ ] ASP.NET 4.5                             Web-Asp-Net45                  
            [ ] CGI                                     Web-CGI                        
            [ ] ISAPI Extensions                        Web-ISAPI-Ext                  
            [ ] ISAPI Filters                           Web-ISAPI-Filter               
            [ ] Server Side Includes                    Web-Includes                   
            [ ] WebSocket Protocol                      Web-WebSockets                 
    [ ] FTP Server                                      Web-Ftp-Server                 
        [ ] FTP Service                                 Web-Ftp-Service                
        [ ] FTP Extensibility                           Web-Ftp-Ext                    
    [ ] Management Tools                                Web-Mgmt-Tools                 
        [ ] IIS Management Console                      Web-Mgmt-Console               
        [ ] IIS 6 Management Compatibility              Web-Mgmt-Compat                
            [ ] IIS 6 Metabase Compatibility            Web-Metabase                   
            [ ] IIS 6 Management Console                Web-Lgcy-Mgmt-Console          
            [ ] IIS 6 Scripting Tools                   Web-Lgcy-Scripting             
            [ ] IIS 6 WMI Compatibility                 Web-WMI                        
        [ ] IIS Management Scripts and Tools            Web-Scripting-Tools            
        [ ] Management Service                          Web-Mgmt-Service               
[ ] IIS Hostable Web Core                               Web-WHC 

Separate each feature you wish to install by a comma on the "Name" parameter. Example:

Install-WindowsFeature -ComputerName SomePCHere -Name Web-Server, Web-Mgmt-Tools, Web-Security

Clients OS's

On Windows 8.1+ you can use the Get-WindowsOptionalFeature and Enable-WindowsOptionalFeature to install IIS.

By running the following you can get the names of the IIS features from PowerShell's point of view:

PS C:\> Get-WindowsOptionalFeature -online | Where {$_.FeatureName -like 'IIS*'} | Sort FeatureName | Format-Table

FeatureName                                   State
-----------                                   -----
IIS-ApplicationDevelopment                 Disabled
IIS-ApplicationInit                        Disabled
IIS-ASP                                    Disabled
IIS-ASPNET                                 Disabled
IIS-ASPNET45                               Disabled
IIS-BasicAuthentication                    Disabled
IIS-CertProvider                           Disabled
IIS-CGI                                    Disabled
IIS-ClientCertificateMappingAuthentication Disabled
IIS-CommonHttpFeatures                     Disabled
IIS-CustomLogging                          Disabled
IIS-DefaultDocument                        Disabled
IIS-DigestAuthentication                   Disabled
IIS-DirectoryBrowsing                      Disabled
IIS-FTPExtensibility                       Disabled
IIS-FTPServer                              Disabled
IIS-FTPSvc                                 Disabled
IIS-HealthAndDiagnostics                   Disabled
IIS-HostableWebCore                        Disabled
IIS-HttpCompressionDynamic                 Disabled
IIS-HttpCompressionStatic                  Disabled
IIS-HttpErrors                             Disabled
IIS-HttpLogging                            Disabled
IIS-HttpRedirect                           Disabled
IIS-HttpTracing                            Disabled
IIS-IIS6ManagementCompatibility            Disabled
IIS-IISCertificateMappingAuthentication    Disabled
IIS-IPSecurity                             Disabled
IIS-ISAPIExtensions                        Disabled
IIS-ISAPIFilter                            Disabled
IIS-LegacyScripts                          Disabled
IIS-LegacySnapIn                           Disabled
IIS-LoggingLibraries                       Disabled
IIS-ManagementConsole                      Disabled
IIS-ManagementScriptingTools               Disabled
IIS-ManagementService                      Disabled
IIS-Metabase                               Disabled
IIS-NetFxExtensibility                     Disabled
IIS-NetFxExtensibility45                   Disabled
IIS-ODBCLogging                            Disabled
IIS-Performance                            Disabled
IIS-RequestFiltering                       Disabled
IIS-RequestMonitor                         Disabled
IIS-Security                               Disabled
IIS-ServerSideIncludes                     Disabled
IIS-StaticContent                          Disabled
IIS-URLAuthorization                       Disabled
IIS-WebDAV                                 Disabled
IIS-WebServer                              Disabled
IIS-WebServerManagementTools               Disabled
IIS-WebServerRole                          Disabled
IIS-WebSockets                             Disabled
IIS-WindowsAuthentication                  Disabled
IIS-WMICompatibility                       Disabled

Similar to windows server, you can install the features above by running the following or something similar (you can install multiple features by using a comma to separate the values on the FeatureName parameter :

#you can add -NoRestart to prevent automatic restarting (if required)
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Webserver

Hope this Helps!

3
  • This is very helpful! Thank you!
    – micah
    Jun 18, 2016 at 5:46
  • I assume this line of code above will also run on Windows 7/8/10, right? After running the .ps1, running as Admin, that I created with Install-WindowsFeature -ComputerName SomePCHere -Name Web-Server, Web-Mgmt-Tools, Web-Security, I go to the Windows Features window in Control Panel > Programs and Features and it doesn't show IIS as installed/enabled. Is there something else I should be doing to make this work on regular Windows?
    – micah
    Jun 20, 2016 at 21:34
  • My initial answer was for Windows server only. I just edited and added a section for client OS's. The client OS part will only work on Windows 8.1+. Jun 22, 2016 at 2:22
3

See Tyler Helder's helpful answer for the full list of IIS-related features and more information about the parameters of the Install-WindowsFeature cmdlet; the focus of this answer is more conceptual.

There's a good chance that the ServerManager PowerShell module comes preinstalled with your Windows server OS (W2K8R2+; note that client OSs require a different method):

If so, you can install IIS as follows:

  • Open an elevated PowerShell console (Run as Administrator)
  • Run Add-WindowsFeature Web-Server

Add-WindowsFeature, present since W2K8R2, was renamed to Install-WindowsFeature in W2K12R2, but Add-WindowsFeature was retained as an alias, so it works in both versions.

To list all server features and their installation status, run Get-WindowsFeature.

Note that it is the values from the Name column that must be provided as arguments to the Add-WindowsFeature / Install-WindowsFeature cmdlets, whereas the DisplayName column often contains the keyword of interest.

Case in point: To discover all features whose display name contains "IIS" - and thereby discover that the name of the IIS feature is Web-Server - run (PSv3+):

Get-WindowsFeature | ? DisplayName -like *IIS*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.