Zwadderich
Zwadderich

Reputation: 251

How to Install IIS 8 through Code

For my Windows 2012 R2 school assignment I need to automatically install IIS 8 on my virtual machine. I guess the best way is with a script. I have found numerous solutions for the UI but non for the cmd. Is there a) a way to automatically install it on every machine with the ui? Or is there b) a script to install IIS 8 on windows?

Thank you in advance.

Upvotes: 2

Views: 1656

Answers (4)

Marty Wiedmeyer
Marty Wiedmeyer

Reputation: 11

Please note: The *-WindowsOptionalFeature cmdlet set can be used for either server or non-server Windows and it enables/disables features that are already in the OS. It is DISM like in that you can work with the online image with the -online switch or with offline images

Servers use *-WindowsFeature cmdlets adds or removes features

Upvotes: 0

Nathan Bedford
Nathan Bedford

Reputation: 9214

You can speed up the time required to enable features by passing all required features as an array instead of a string.

You can also use the 'All' parameter. It "Enables all parent features of the specified feature. If a parent feature is required for the specified feature to be enabled in the image, All will enable the parent and all of its default dependencies." 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

Upvotes: 0

Peter Hahndorf
Peter Hahndorf

Reputation: 11222

On Server 2012 R2, you can use the Enable-WindowsOptionalFeature cmdlet, to install the default IIS use:

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

to pick optional feature, build a custom script using some of the following:

# 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

Upvotes: 5

anil
anil

Reputation: 1001

You can Install IIS 8 using the Powershell using command listed in following link https://technet.microsoft.com/en-us/magazine/dn236383.aspx.

Upvotes: 0

Related Questions