使用腳本自動安裝window的IIS功能

需求場景: 我們想讓我們軟件安裝的時候自動安裝好操作系統的IIS環境
實現思路:

  • window server 2012及以上 使用powershell
    使用Install-WindowsFeature命令,如:Install-WindowsFeature -Name Web-CGI就是在安裝CGI功能
    那麼如何知道安裝IIS都需要哪些命令呢?
    可以使用命令get-windowsfeature |fl |out-file c:\log.log將支持的所有window功能列出來,對比列出來的功能和自己手動安裝時的嚮導發現他們是對應的,打印出來如下:
Display Name                                            Name                       Install State
------------                                            ----                       -------------
[ ] Active Directory Federation Services                ADFS-Federation                Available
[ ] Active Directory Rights Management Services         ADRMS                          Available
    [ ] Active Directory 權限管理服務器                 ADRMS-Server                   Available
..........

完整的IIS安裝命令如下:

Install-WindowsFeature -Name Web-Server
Install-WindowsFeature -Name Web-WebServer
Install-WindowsFeature -Name Web-Security
Install-WindowsFeature -Name Web-Filtering
Install-WindowsFeature -Name Web-Cert-Auth
Install-WindowsFeature -Name Web-IP-Security
Install-WindowsFeature -Name Web-Url-Auth
Install-WindowsFeature -Name Web-Windows-Auth
Install-WindowsFeature -Name Web-Basic-Auth
Install-WindowsFeature -Name Web-Client-Auth
Install-WindowsFeature -Name Web-Digest-Auth
Install-WindowsFeature -Name Web-Common-Http
Install-WindowsFeature -Name Web-Http-Errors
Install-WindowsFeature -Name Web-Static-Content
Install-WindowsFeature -Name Web-Default-Doc
Install-WindowsFeature -Name Web-Dir-Browsing
Install-WindowsFeature -Name Web-Http-Redirect
Install-WindowsFeature -Name Web-Stat-Compression
Install-WindowsFeature -Name Web-App-Dev
Install-WindowsFeature -Name Web-Net-Ext45
Install-WindowsFeature -Name Web-ASP
Install-WindowsFeature -Name Web-Asp-Net
Install-WindowsFeature -Name Web-Asp-Net45
Install-WindowsFeature -Name Web-CGI;
Install-WindowsFeature -Name Web-ISAPI-Ext;
Install-WindowsFeature -Name Web-ISAPI-Filter;
Install-WindowsFeature -Name Web-Includes;
Install-WindowsFeature -Name Web-Mgmt-Tools;
Install-WindowsFeature -Name Web-Mgmt-Console;
Install-WindowsFeature -Name Web-Mgmt-Compat;
Install-WindowsFeature -Name Web-Metabase;
Install-WindowsFeature -Name Web-WMI;
Install-WindowsFeature -Name Web-Lgcy-Scripting;
Install-WindowsFeature -Name Web-Scripting-Tools;
Install-WindowsFeature -Name Web-Mgmt-Service;
Install-WindowsFeature -Name AS-NET-Framework;
Install-WindowsFeature -Name AS-TCP-Port-Sharing;
Install-WindowsFeature -Name AS-Web-Support;
Install-WindowsFeature -Name AS-WAS-Support;
Install-WindowsFeature -Name AS-HTTP-Activation;
Install-WindowsFeature -Name AS-TCP-Activation;
Install-WindowsFeature -Name NET-Framework-Features
Install-WindowsFeature -Name NET-Framework-Core
Install-WindowsFeature -Name NET-Framework-45-Features
Install-WindowsFeature -Name NET-Framework-45-Core;
Install-WindowsFeature -Name NET-Framework-45-ASPNET;
Install-WindowsFeature -Name NET-WCF-Services45;
Install-WindowsFeature -Name NET-WCF-TCP-PortSharing45;
Install-WindowsFeature -Name NET-WCF-TCP-Activation45;
Install-WindowsFeature -Name NET-WCF-HTTP-Activation45;
Install-WindowsFeature -Name NET-WCF-TCP-Activation45;
  • window serer 2008版本
    由於不支持Install-WindowsFeature命令,所以使用pkgmgr代替,完整的安裝命令如下:
pkgmgr /quiet /iu:IIS-WebServerRole;
pkgmgr /quiet /iu:IIS-WebServer;
pkgmgr /quiet /iu:IIS-CommonHttpFeatures;
pkgmgr /quiet /iu:IIS-StaticContent;
pkgmgr /quiet /iu:IIS-DefaultDocument;
pkgmgr /quiet /iu:IIS-DirectoryBrowsing;
pkgmgr /quiet /iu:IIS-HttpErrors;
pkgmgr /quiet /iu:IIS-HttpRedirect;
pkgmgr /quiet /iu:IIS-ApplicationDevelopment;
pkgmgr /quiet /iu:IIS-ASPNET;
pkgmgr /quiet /iu:IIS-NetFxExtensibility;
pkgmgr /quiet /iu:IIS-ASP;
pkgmgr /quiet /iu:IIS-ISAPIExtensions;
pkgmgr /quiet /iu:IIS-ISAPIFilter;
pkgmgr /quiet /iu:IIS-ServerSideIncludes;
pkgmgr /quiet /iu:IIS-HealthAndDiagnostics;
pkgmgr /quiet /iu:IIS-HttpLogging;
pkgmgr /quiet /iu:IIS-LoggingLibraries;
pkgmgr /quiet /iu:IIS-RequestMonitor;
pkgmgr /quiet /iu:IIS-HttpTracing;
pkgmgr /quiet /iu:IIS-CustomLogging;
pkgmgr /quiet /iu:IIS-ODBCLogging;
pkgmgr /quiet /iu:IIS-Security;
pkgmgr /quiet /iu:IIS-BasicAuthentication;
pkgmgr /quiet /iu:IIS-WindowsAuthentication;
pkgmgr /quiet /iu:IIS-DigestAuthentication;
pkgmgr /quiet /iu:IIS-ClientCertificateMappingAuthentication;
pkgmgr /quiet /iu:IIS-IISCertificateMappingAuthentication;
pkgmgr /quiet /iu:IIS-URLAuthorization;
pkgmgr /quiet /iu:IIS-RequestFiltering;
pkgmgr /quiet /iu:IIS-IPSecurity;
pkgmgr /quiet /iu:IIS-Performance;
pkgmgr /quiet /iu:IIS-HttpCompressionStatic;
pkgmgr /quiet /iu:IIS-HttpCompressionDynamic;
pkgmgr /quiet /iu:IIS-WebServerManagementTools;
pkgmgr /quiet /iu:IIS-ManagementConsole;
pkgmgr /quiet /iu:IIS-ManagementScriptingTools;
pkgmgr /quiet /iu:IIS-ManagementService;
pkgmgr /quiet /iu:IIS-IIS6ManagementCompatibility;
pkgmgr /quiet /iu:IIS-Metabase;
pkgmgr /quiet /iu:IIS-WMICompatibility;
pkgmgr /quiet /iu:IIS-LegacyScripts;
pkgmgr /quiet /iu:IIS-LegacySnapIn;
pkgmgr /quiet /iu:WAS-WindowsActivationService;
pkgmgr /quiet /iu:WAS-ProcessModel;
pkgmgr /quiet /iu:WAS-NetFxEnvironment;
pkgmgr /quiet /iu:WAS-ConfigurationAPI

另附:
Install-WindowsFeature命令文檔地址:
https://docs.microsoft.com/zh-cn/previous-versions/windows/powershell-scripting/jj205467(v=wps.620)
get-windowsfeature命令文檔地址:
https://docs.microsoft.com/zh-cn/previous-versions/windows/powershell-scripting/jj205469(v=wps.630)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章