参考Windows2008 2012 2016 2019 IIS7.5 8.0 10.0 一键安装脚本BAT安装脚本发布 – 笔戈 (biger.me),使用DISM重新实现

技巧:

可先手工安装IIS各项功能后,在命令行中使用dism /online /get-features >f.txt 得到各项功能的名称,然后在脚本中针对性的启用或禁用

@@@code

部署映像服务和管理工具

版本: 6.3.9600.17031

映像版本: 6.3.9600.17031

程序包功能列表 : Microsoft-Windows-Foundation-Package~31bf3856ad364e35~amd64~~6.3.9600.16384

功能名称 : Microsoft-Hyper-V-All

状态 : 已禁用

功能名称 : Microsoft-Hyper-V-Tools-All

状态 : 已禁用

功能名称 : Microsoft-Hyper-V

状态 : 已禁用

功能名称 : Microsoft-Hyper-V-Management-Clients

状态 : 已禁用

功能名称 : Microsoft-Hyper-V-Management-PowerShell

状态 : 已禁用

功能名称 : Printing-Foundation-Features

状态 : 已启用

功能名称 : Printing-Foundation-LPRPortMonitor

状态 : 已禁用

功能名称 : Printing-Foundation-LPDPrintService

状态 : 已禁用

@@#

@@@code

@echo off

title IIS一键安装脚本

color 5e

rem mode con cols=30 lines=5

rem 2008 r2 or win7

ver | find “6.1.7600” > NUL && goto :win2008

rem 2008 r2 sp1 or win7 sp1

ver | find “6.1.7601” > NUL && goto :win2008

rem 8.1 or 2012

ver | find “6.3.9600” > NUL && goto :win2012

rem 2016

ver | find “10.0.14” > NUL && goto :win2012

rem 2019

ver | find “10.0.17” > NUL && goto :win2012

rem 10

ver | find “10.0.19” > NUL && goto :win2012

echo 无法识别当前系统版本,进行默认安装

ver

goto :win2012

pause

exit

:win7

rem pkgmgr方式

echo 正在安装IIS这可能需要几分钟…

start /w pkgmgr /iu:IIS-WebServerRole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

echo 正在启用IIS功能

start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;

echo 管理工具

start /w pkgmgr /iu:IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;

rem IIS-WebServerManagementToolsIIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;IIS-FTPPublishingService;IIS-FTPServer;IIS-FTPManagement;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

echo 运行状况和诊断

start /w pkgmgr /iu:IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;

rem start /w pkgmgr /iu:IIS-ODBCLogging;IIS-CustomLogging;IIS-RequestMonitor;IIS-HttpTracing;

echo 性能

start /w pkgmgr /iu:IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;

echo 安全性

start /w pkgmgr /iu:IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication

echo 应用程序

start /w pkgmgr /iu:IIS-ApplicationDevelopment;IIS-NetFxExtensibility;IIS-ServerSideIncludes;NetFx3;

start /w pkgmgr /iu:IIS-ASPNET;IIS-ISAPIExtensions;IIS-ISAPIFilter;

start /w pkgmgr /iu:NET-HTTP-Activation;NET-Non-HTTP-Activ;

start /w pkgmgr /iu:NET-WCF-Pipe-Activation;NET-WCF-HTTP-Activation;

start /w pkgmgr /iu:WCF-HTTP-Activation;WCF-NonHTTP-Activation;

rem start /w pkgmgr /iu:IIS-ASP;IIS-CGI;

rem ;IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;

goto :kuaijie

:win2008

echo 正在启用Net Framework3.5

DISM /Online /Enable-Feature /FeatureName:NetFx3

echo 正在安装IIS这可能需要几分钟…

dism /Online /Enable-Feature /FeatureName:IIS-WebServerRole /FeatureName:IIS-WebServer /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpRedirect /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-HttpLogging /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-Security /FeatureName:IIS-RequestFiltering /FeatureName:IIS-Performance /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-Metabase /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-StaticContent /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-ISAPIExtensions /FeatureName:WAS-WindowsActivationService /FeatureName:WAS-ProcessModel /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment

echo 正在启用IIS功能

dism /Online /Enable-Feature /FeatureName:IIS-ASPNET /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-HostableWebCore /FeatureName:WCF-HTTP-Activation /FeatureName:WAS-NetFxEnvironment /FeatureName:WCF-NonHTTP-Activation /FeatureName:WCF-HTTP-Activation

goto :kuaijie

:win2012

echo 正在启用Net Framework3.5

DISM /Online /Enable-Feature /FeatureName:NetFx3 /All

echo 正在安装IIS这可能需要几分钟…

dism /Online /Enable-Feature /FeatureName:IIS-WebServerRole /FeatureName:IIS-WebServer /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpRedirect /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-HttpLogging /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-Security /FeatureName:IIS-RequestFiltering /FeatureName:IIS-Performance /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-Metabase /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-StaticContent /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-ISAPIExtensions /FeatureName:WAS-WindowsActivationService /FeatureName:WAS-ProcessModel /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment /FeatureName:NetFx4Extended-ASPNET45

echo 正在启用IIS功能

dism /Online /Enable-Feature /FeatureName:IIS-ASPNET /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-HostableWebCore /FeatureName:WCF-HTTP-Activation /FeatureName:WAS-NetFxEnvironment /FeatureName:WCF-NonHTTP-Activation /FeatureName:WCF-HTTP-Activation /FeatureName:WCF-HTTP-Activation45 /FeatureName:IIS-ASPNET45 /FeatureName:WCF-Services45 /FeatureName:IIS-NetFxExtensibility45

goto :kuaijie

:kuaijie

start /w pkgmgr /iu:TelnetClient

echo 正在创建IIS桌面快捷方式

echo [InternetShortcut] >>”C:\Users\Administrator\Desktop\Internet 信息服务(IIS)管理器.url”

echo URL=”%SystemRoot%\system32\inetsrv\InetMgr.exe” >>”C:\Users\Administrator\Desktop\Internet 信息服务(IIS)管理器.url”

echo IconIndex=0 >>”C:\Users\Administrator\Desktop\Internet 信息服务(IIS)管理器.url”

echo IconFile=”%SystemRoot%\system32\inetsrv\InetMgr.exe” >>”C:\Users\Administrator\Desktop\Internet 信息服务(IIS)管理器.url”

echo IIS安装完成

pause

exit

@@#

Windows 7

Windows 7 sp1

Windows 2008 R2

Windows 2008 r2 sp1

Windows 8.1

Windows 2012 r2

Windows 2016

Windows 2019

Windows 10