PowerShell – Stage 2

In this part of PowerShell topic I will show you how to create IIS website and unzip Sitecore into the new site directory.

Set site name

Before we will do a real job we have to define name of our new site. We can ask user in console to set the value. This code will prompt for name:

As result we will have name saved in variable $nameProvidedByUser.

Stop IIS

Because we have to add new ApplicationPool, create new IIS Site, sometimes also override some values in confiugration – it is better to stop our local instance of IIS before we will start.

We can do this with script:

After that definition we have to just call our function with command “IISStop”

Do some real work – define/copy/run

Ok, for now we have defined name and stopped IIS instance. We are ready to do some real work.

Run following command and at the end you will have ready to work IIS site and copied Sitecore files inside web root.

We have here code for:

  • unpacking ZIP files
  • changing the structure of unpacked files
  • creation of IIS AppPool
  • creation of IIS Site
  • creation of settings for bindings

But what exactly this command will do? Here you have explanation.

Inside this block of code we use some functions which were prepared before.

Add host to Windows file

If we want to define new site in our environment we also should add new definition in windows hosts file. We can do this with following script:

Start IIS

Because we have in plan to stop our IIS we also should have a script to start it again.

We can do this with following function:

Select version of Sitecore

Probably you will have more than one version of Sitecore in your files system – it means that would be nice to have an option to select which version of Sitecore should be copied into our web root. We can provide that feature with code:

What’s next?

In next part of PowerShell fun I am going to refactor code and set some settings like:

  • permissions
  • database connection strings

If you want to check how current version works you can checkout (and later also participate) code from my public repository on GitHub : PowerShell-automation

Notify of
Inline Feedbacks
View all comments