自动安装IIS

时间:2016-06-18 00:37:37

标签: windows powershell iis automation

目标是在新的Windows工作站(如Windows 10)上为.NET开发环境自动启用IIS。我意识到可以编写Powershell脚本来做这样的事情,但我不知道从哪里开始。

我意识到我可以轻松进入控制面板并在那里启用服务,但是运行脚本来执行此操作似乎更有效。

将在Powershell中运行以启用IIS的示例脚本是什么样的?

2 个答案:

答案 0 :(得分:12)

服务器操作系统

在Windows Server上,您可以运行以下命令来自动安装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

以下是PowerShell的IIS功能名称:

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 

在"名称"上用逗号分隔您要安装的每个功能。参数。例如:

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

客户操作系统

在Windows 8.1+上,您可以使用Get-WindowsOptionalFeatureEnable-WindowsOptionalFeature安装IIS。

通过运行以下命令,您可以从PowerShell的角度获取IIS功能的名称:

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

与Windows服务器类似,您可以通过运行以下或类似的东西来安装上述功能(您可以使用逗号分隔FeatureName参数上的值来安装多个功能:

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

希望这有帮助!

答案 1 :(得分:3)

有关IIS相关功能的完整列表以及有关Tyler Helder's helpful answer cmdlet参数的详细信息,请参阅Install-WindowsFeature; 这个答案的重点更具概念性。

ServerManager PowerShell模块很可能预装了Windows 服务器操作系统(W2K8R2 +;请注意客户端操作系统require a different method):

如果是这样,您可以安装IIS,如下所示

  • 打开提升 PowerShell控制台(以管理员身份运行)
  • 运行Add-WindowsFeature Web-Server
自W2K8R2以来

Add-WindowsFeature在W2K12R2中重命名为Install-WindowsFeature ,但Add-WindowsFeature保留为别名,所以它适用于两个版本。

列出所有服务器功能及其安装状态,请运行Get-WindowsFeature

请注意,来自Name列的值必须作为Add-WindowsFeature / Install-WindowsFeature cmdlet 的参数提供,而{{1>通常包含感兴趣的关键字。

实例:发现显示名称包含“IIS”的所有功能 - 从而发现IIS功能的名称为DisplayName column - 运行(PSv3 +):

Web-Server