Generate IIS application with Powershell based on a list

powershellHere’s another simple code snippet to create an IIS application, set the name, physical path, protocol and set the version of the runtime for the AppPool. In that case we use a list of objects representing the applications we have to create.

# First load the mgmt module
import-module webadministration 
foreach($Application in $Applications)
{
	# Check if the app is not already existing. If yes, delete it.
	if(Test-Path 'iis:\Sites\Default Web Site\'$Application.Name)
	{
		# Delete the existing application
		Remove-Item 'iis:\Sites\Default Web Site\'$Application.Name
	}
	# Create the new one
	New-Item 'iis:\Sites\Default Web Site\'$Application.Name -physicalPath $Application.Path -type Application
	# Set the protocol
	Set-ItemProperty 'iis:\Sites\Default Web Site\'$Application.Name  -Name "enabledProtocols" -Value "http,net.tcp"
}
# Set the runtime version
Set-ItemProperty 'iis:\AppPools\DefaultAppPool' -name managedRuntimeVersion -Value 'v4.0'

Catch you next time and keep it bug free !

Published by Emmanuel Istace

Musician, Software developer and guitar instructor. https://emmanuelistace.be/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: