PowerShell ways to install IIS7.x
We’re talking here about PowerShell and IIS; maybe the first thing to do should have been to install IIS (7.x) with PowerShell…
In the following examples, we’ll see a “minimal” (Server Core compliant) installation of IIS. The only purpose is to see the different ways to do it, not to have a proper installation, which will be the point of a future post. So, I mean the following list of role and features:
- Web Server (IIS)
- Internet Information Services (Web Server)
- Common HTTP Features
- Static Content
- Default Document
- Directory Browsing
- HTTP Errors
- Health and Diagnostics
- HTTP Logging
- Logging Tools
- Request Monitor
- Security
- Request Filtering
- Static Content Compression
- Management Tools
- Windows Process Activation Service
- Windows Process Activation Service – Process Model
For the complete list of available role and feature, have a look at the documentation: Web Server (IIS) Role
So, let’s have some fun. There’s (at least) 3 ways to do it:
- pkgmgr (Package Manager Command-Line)
- pkgmgr (Package Manager Command-Line) with an unattend file
- Add-WindowsFeature (Add-WindowsFeature Cmdlet)
Start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;WAS-WindowsActivationService;WAS-ProcessModel
# Gets the date in a string variable for logfile naming $date=(Get-Date).ToString('dd-MM-yyyy') # Gets the OS Version number to append the unattend.xml file $OSInstallVer = $(Get-ItemProperty HKLM:\Software\Microsoft\DataAccess).FullInstallVer (Get-Content .\unattend.xml) | ForEach-Object {$_ -replace "OS-VERSION-NB", "$OSInstallVer"} | Set-Content .\unattend.xml Start /w pkgmgr /n:.\unattend.xml /l:.\install-IIS-$date.log
The unattend file
<?xml version="1.0" ?> <unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"> <servicing> <!-- Install a selectable update in a package that is in the Windows Foundation namespace --> <package action="configure"> <assemblyIdentity name="Microsoft-Windows-Foundation-Package" version="OS-VERSION-NB" language="neutral" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" versionScope="nonSxS" /> <selection name="IIS-WebServerRole" state="true"/> <selection name="IIS-WebServer" state="true"/> <selection name="IIS-CommonHttpFeatures" state="true"/> <selection name="IIS-HttpErrors" state="false"/> <selection name="IIS-HttpRedirect" state="false"/> <selection name="IIS-ApplicationDevelopment" state="false"/> <selection name="IIS-NetFxExtensibility" state="false"/> <selection name="IIS-HealthAndDiagnostics" state="true"/> <selection name="IIS-HttpLogging" state="true"/> <selection name="IIS-LoggingLibraries" state="true"/> <selection name="IIS-RequestMonitor" state="true"/> <selection name="IIS-HttpTracing" state="false"/> <selection name="IIS-Security" state="true"/> <selection name="IIS-URLAuthorization" state="false"/> <selection name="IIS-RequestFiltering" state="true"/> <selection name="IIS-IPSecurity" state="true"/> <selection name="IIS-Performance" state="false"/> <selection name="IIS-HttpCompressionDynamic" state="false"/> <selection name="IIS-WebServerManagementTools" state="true"/> <selection name="IIS-ManagementScriptingTools" state="false"/> <selection name="IIS-IIS6ManagementCompatibility" state="false"/> <selection name="IIS-Metabase" state="false"/> <selection name="WAS-WindowsActivationService" state="true"/> <selection name="WAS-ProcessModel" state="true"/> <selection name="WAS-NetFxEnvironment" state="false"/> <selection name="WAS-ConfigurationAPI" state="false"/> <selection name="IIS-HostableWebCore" state="false"/> <selection name="IIS-StaticContent" state="true"/> <selection name="IIS-DefaultDocument" state="true"/> <selection name="IIS-DirectoryBrowsing" state="true"/> <selection name="IIS-WebDAV" state="false"/> <selection name="IIS-ASPNET" state="false"/> <selection name="IIS-ASP" state="false"/> <selection name="IIS-CGI" state="false"/> <selection name="IIS-ISAPIExtensions" state="false"/> <selection name="IIS-ISAPIFilter" state="false"/> <selection name="IIS-ServerSideIncludes" state="false"/> <selection name="IIS-CustomLogging" state="false"/> <selection name="IIS-BasicAuthentication" state="false"/> <selection name="IIS-HttpCompressionStatic" state="true"/> <selection name="IIS-ManagementConsole" state="false"/> <selection name="IIS-ManagementService" state="false"/> <selection name="IIS-WMICompatibility" state="false"/> <selection name="IIS-LegacyScripts" state="false"/> <selection name="IIS-LegacySnapIn" state="false"/> <selection name="IIS-FTPServer" state="false"/> <selection name="IIS-FTPSvc" state="false"/> <selection name="IIS-FTPExtensibility" state="false"/> <selection name="IIS-WindowsAuthentication" state="false"/> <selection name="IIS-DigestAuthentication" state="false"/> <selection name="IIS-ClientCertificateMappingAuthentication" state="false"/> <selection name="IIS-IISCertificateMappingAuthentication" state="false"/> <selection name="IIS-ODBCLogging" state="false"/> </package> </servicing> </unattend>
Add-WindowsFeature -Name Web-Server,Web-WebServer,Web-Common-Http,Web-Static-Content,Web-Default-Doc,Web-Dir-Browsing,Web-Http-Errors,Web-Health,Web-Http-Logging,Web-Log-Libraries,Web-Request-Monitor,Web-Security,Web-Filtering,Web-Stat-Compression,Web-Mgmt-Tools,WAS,WAS-Process-Model