windows - 自动安装 IIS

标签 windows powershell iis automation

目标是在新的 Windows 工作站(如 Windows 10)上为 .NET 开发环境自动启用 IIS。我知道可以编写 Powershell 脚本来执行类似的操作,但我不知道从哪里开始。

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

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

最佳答案

服务器操作系统

在 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

希望对您有所帮助!

关于windows - 自动安装 IIS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37892173/

相关文章:

c++ - 如何在不改变所有文本颜色的情况下设置单个单词的颜色?

r - 在 Windows 上截断大文件

powershell - 在 foreach 中导出多个输出

sql-server - 如何通过 PowerShell (Azure CLI) 启用 "Allow Azure services and resources to access this server"?

arrays - 创建并填充哈希表

asp.net - ASP .NET 中的重复任务

asp.net - 在本地主机上应用 SSL

asp.net - 无法停止为静态内容触发 ASP.NET 模块

c - 如何在静态控件中画线?

Spring Boot 3 Native 构建问题 - 拨号 tcp 查找超时