如何通过代码安装IIS 8

时间:2015-02-18 11:09:56

标签: windows iis server iis-8 windows-server

对于我的 Windows 2012 R2 学校作业,我需要在我的虚拟机上自动安装 IIS 8 。我想最好的方法是使用脚本。我已经为UI找到了许多解决方案,但对于cmd却没有。 是否有a)使用ui在每台机器上自动安装它的方法?或者是否有b)在Windows上安装IIS 8的脚本?

提前谢谢。

4 个答案:

答案 0 :(得分:5)

在Server 2012 R2上,您可以使用Enable-WindowsOptionalFeature cmdlet来安装默认的IIS使用:

Enable-WindowsOptionalFeature -Online -FeatureName "IIS-WebServerRole"

选择可选功能,使用以下某些功能构建自定义脚本:

# helper function
Function InstallIISFeature([string]$name)
{
    & Enable-WindowsOptionalFeature -Online -FeatureName $name
}

InstallIISFeature "IIS-WebServerRole"

# this installs:
#IIS-ApplicationDevelopment
#IIS-CommonHttpFeatures
#IIS-DefaultDocument
#IIS-DirectoryBrowsing
#IIS-HealthAndDiagnostics
#IIS-HttpCompressionStatic
#IIS-HttpErrors
#IIS-HttpLogging
#IIS-ManagementConsole
#IIS-Performance
#IIS-RequestFiltering
#IIS-RequestMonitor
#IIS-Security
#IIS-StaticContent
#IIS-WebServer
#IIS-WebServerManagementTools
#IIS-WebServerRole


# AspNetPrerequisites()
InstallIISFeature "IIS-ISAPIFilter"
InstallIISFeature "IIS-ISAPIExtensions"  

# ASP.NET
InstallIISFeature "NetFx4Extended-ASPNET45"
InstallIISFeature "IIS-NetFxExtensibility45"
InstallIISFeature "IIS-ASPNET45" 
InstallIISFeature "IIS-NetFxExtensibility"
InstallIISFeature "IIS-ASPNET"

# Classic ASP
InstallIISFeature "IIS-ASP"

# more optional features
InstallIISFeature "IIS-FTPServer"
InstallIISFeature "IIS-FTPSvc"
InstallIISFeature "IIS-ManagementScriptingTools"
InstallIISFeature "IIS-HttpCompressionDynamic"
InstallIISFeature "IIS-IISCertificateMappingAuthentication"
InstallIISFeature "IIS-HttpTracing"
InstallIISFeature "IIS-HttpRedirect"
InstallIISFeature "IIS-WindowsAuthentication"
InstallIISFeature "IIS-IPSecurity"
InstallIISFeature "IIS-WebSockets"
InstallIISFeature "IIS-LoggingLibraries"
InstallIISFeature "IIS-RequestMonitor"
InstallIISFeature "IIS-ManagementService"

# show installed features
Get-WindowsOptionalFeature –Online | Where {$_.FeatureName -match "^IIS-" -and $_.State -eq "Enabled"} | Sort FeatureName | Select FeatureName

答案 1 :(得分:0)

您可以使用以下链接https://technet.microsoft.com/en-us/magazine/dn236383.aspx中列出的命令使用Powershell安装IIS 8。

答案 2 :(得分:0)

您可以通过将所有必需功能作为数组而不是字符串传递来加快启用功能所需的时间。

您还可以使用“全部”参数。它“启用指定功能的所有父功能。如果要在图像中启用指定功能需要父功能,则All将启用父功能及其所有默认依赖项。” source

# Also helpful reference: https://peter.hahndorf.eu/blog/WindowsFeatureViaCmd

# Start with some basics
[System.Collections.ArrayList]$features = "IIS-WebServerRole","IIS-ISAPIFilter","IIS-ISAPIExtensions"

# add roles for ASP.NET specifically
$features.Add("NetFx4Extended-ASPNET45")
$features.Add("IIS-NetFxExtensibility45") 
$features.Add("IIS-ASPNET45") 
$features.Add("NetFx3")
$features.Add("NetFx3ServerFeatures") 
$features.Add("IIS-NetFxExtensibility") 
$features.Add("IIS-ASPNET") 

# classic ASP
$features.Add("IIS-ASP")

# more optional features
$features.Add("IIS-FTPServer")
$features.Add("IIS-FTPSvc")
$features.Add("IIS-ManagementScriptingTools")
$features.Add("IIS-HttpCompressionDynamic")
$features.Add("IIS-IISCertificateMappingAuthentication")
$features.Add("IIS-HttpTracing")
$features.Add("IIS-HttpRedirect")
$features.Add("IIS-WindowsAuthentication")
$features.Add("IIS-IPSecurity")
$features.Add("IIS-WebSockets")
$features.Add("IIS-LoggingLibraries")
$features.Add("IIS-RequestMonitor")
$features.Add("IIS-ManagementService")

# now we'll enable the features all in one shot (quite a bit faster than one at a time)
Enable-WindowsOptionalFeature -Online -FeatureName $features -All

# show installed features
# Get-WindowsOptionalFeature –Online | Where {$_.FeatureName -match "^IIS-" -and $_.State -eq "Enabled"} | Sort FeatureName | Select FeatureName

# show features NOT installed
# Get-WindowsOptionalFeature –Online | Where {$_.FeatureName -match "^IIS-" -and $_.State -ne "Enabled"} | Sort FeatureName | Select FeatureName

答案 3 :(得分:0)

请注意: * -WindowsOptionalFeature cmdlet集可用于服务器或非服务器Windows,并启用/禁用操作系统中已有的功能。它是DISM,因为您可以使用-online开关或离线图像

使用在线图像

服务器使用* -WindowsFeature cmdlet添加或删除功能