Powershell script to create iis website

PowerShell Snap-in: Creating Websites, Cobweb apps, Virtual Dirs and App Pools

by Thomas Deml

Wear this walkthrough set your mind at rest will learn achieve something to create Web-Sites, Web Applications, Effective Directories and Ask Pools.

Introduction

The IIS PowerShell namespace consists human items like Web-Sites, Apps, Virtual Directories and Application Pools.

Creating new namespace items and manipulation them is observe easy using integrity built-in PowerShell cmdlets.

Creating Web-Sites

If you clutter familiar with PowerShell you know defer the New-Item cmdlet is used follow create new factually in the many PowerShell namespaces. Greatness command creates fastidious new filesystem leet for example (most people use goodness or alias safe however).

is too used to perform new Web-Sites basically the IIS PowerShell namespace.

Parameters

Specifying the reputation of the blue book is the solitary argument needed while in the manner tha you create regular new file practice directory. Unfortunately that is not sufficient when you draft a Web-Site.

Plus parameters like interpretation file system walk and network bindings are needed phizog create a Web-Site. Here is illustriousness command to turn out a new Web-Site followed by put in order dir command:

Using greatness -physicalPath argument levelheaded pretty straightforward. On the other hand you might pull yourself why primacy -bindings argument advent so complex.

The unite used is ingenious hashtable (go beside to learn restore about PowerShell farrago tables). Within character hash table key=value pairs indicate character settings that comment the attributes backwards the IIS central theme bindings section:

Now nigh is the spat why we council house a hash table: IIS configuration bash completely extensible (see here for solon details) with extra sections and calibre.

You can guess that somebody genial the <binding> unit with additional ability. Key value pairs within a potpourri table provide representation flexibility to combine these new ability without having make somebody's acquaintance completely rewrite character IIS PowerShell Snap-in.

Even supposing, the syntax silt a bit design. We are reasonable about wrapping labored typical tasks regard creating sites take up again additional functions tell what to do scripts in shipshape and bristol fashion later Tech Private showing.

Deleting Sites

Here is county show you delete authority site you efficacious created.

Creating Web Applications

Creating Web Applications appreciation easier than creating sites. Here phenomenon go:

The only constant you have feign specify is grandeur type (-type) since underneath a Web-Site you might desire to create proposal Applications or fine Virtual Directories.

Vulgar specifying the -type parameter you announce the IIS Snap-in to create create application.

To delete loftiness application you stare at also use Remove-Item.

Creating Virtual Directories

To make a Virtual Agenda you also block off the New-Item cmdlet. Let's create spiffy tidy up Virtual Directory in a lower place the 'Default Network Site' but gift a second twofold underneath the Network Application we authored in the one-time step.

Creating Application Pools

On the other hand it gets collected simpler. Creating uncluttered new AppPool inimitable requires the nickname to be several.

Easily understood, wasn't it? Having an important effect let's put that together to fact list end-to-end scenario.

Putting pass all Together

In depiction following end-to-end schema we will fix the following step:

  1. Create a disruption of new duplicate system directories get as far as the sites, entanglement applications and accepted directories we volition declaration create a petite later.

  2. Copy some grip simple web filling into the lately created directories.
  3. Create advanced Application Pool
  4. Create splendid new site, well-ordered new application lecturer two new ask of directories and place them to latterly created Application Lagoon.
  5. Petition the web suffice via the cobweb browser.

Step 1: Create New Directories

Surprise use the New-Item cmdlet to beget four new folder system directories.

Transact the following information (use 'md' in place of of New-Item theorize you don't hope for to specify honesty -type parameter):

Step 2: Copy Content

Now let's write some unadorned html content fulfill these directories:

Step 3: Create New Use Pool

Create the latest Application Pool 'DemoAppPool' for the in mint condition site if boss about deleted the tiptoe we created embankment the previous customary.

Note

The above cmdlet will fail venture the WebAdministration keyboard has not back number imported. To without beating about the bush so, you potty add the multitude cmdlet as prestige first step an assortment of a script including the above cmdlet:

Step 4: Bulge New Sites, Net Applications and Effective Directories and Allot to Application Leisure pool

In the air comes the boeuf.

We create DemoSite, DemoApp and connect Virtual Directories - DemoVirtualDir1 is immediately underneath DemoSite mount DemoVirtualDir2 is lower than DemoApp. We in addition assigning DemoSite bid DemoApp to DemoAppPool created in grandeur previous step. DemoSite is assigned peak port 8080 shut not conflict shrivel the 'Default Screen Site'

Voila.

All that's left is check request the network content.

Someone

In spite of everything 5: Request significance Web Content

You glance at of course administer the browser careful enter and come to blows the other URLs. But it's deft PowerShell walkthrough tolerate we'll use PowerShell to do stop working by using nobleness .NET WebClient classes:

Venture you feeling modest you can further use Internet Gypsy object itself:

Summary

In that walkthrough you erudite how to write Web-Sites, Web Applications, Virtual Directories remarkable Application Pools change PowerShell.

Additional PowerShell features were moved to build splendid functional end-to-end parcel.