PowerShell to setup IIS

I’m currently working on a infrastructure management solution. The solution will have a ASP.NET Web API RESTful interface to communicate with devices ‘in the wild’ and a ASP.NET Web MVC Razor Web Application to manage these devices. Of course both projects will be hosted in IIS (onPremise for the moment).

Following PowerShell Script have been used to setup IIS on a Windows Server 2019.

Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Security -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestFiltering -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-StaticContent -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DirectoryBrowsing -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility45 -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HealthAndDiagnostics -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpLogging -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Performance -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName WAS-WindowsActivationService -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName WAS-ProcessModel -NoRestart
# WAS-NetFxEnvironment has parent features -All tells the installer to include them. 
# If you don't include -All Switch you'll get: 
# Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
Enable-WindowsOptionalFeature -Online -FeatureName WAS-NetFxEnvironment -NoRestart -All
Enable-WindowsOptionalFeature -Online -FeatureName WCF-Services45 -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName WCF-TCP-PortSharing45 -NoRestart

And because sometimes somethings don’t work (anymore) as they should, i used this script to remove and IIS before i reinstalled the IIS feature using the script above.

Disable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-Security -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-RequestFiltering -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-StaticContent -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-DirectoryBrowsing -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility45 -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-HealthAndDiagnostics -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-HttpLogging -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-Performance -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName WAS-WindowsActivationService -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName WAS-ProcessModel -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName WAS-NetFxEnvironment -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName WCF-Services45 -NoRestart
Disable-WindowsOptionalFeature -Online -FeatureName WCF-TCP-PortSharing45 -NoRestart