Powershell Script to Create DotNetNuke Site

powershell script for dotnetnuke

Powershell Script to Create DotNetNuke Site


What is Powershell Script

If you find yourself creating a new instance of DotNetNuke on a regular basis and are getting tired of repeating the steps:

  1. Create a new database
  2. Create a new folder to hold your site
  3. Finding a version of DNN and unzipping it to this folder
  4. Adding a new IIS application using the previously created folder path.
  5. Opening a browser and typing in the url to this new site.

Then this is the script for you!

The script takes two parameters.

  • applicationName – Used to create a folder and application name in IIS
  • version – Selects the version to install
param (
    [string]$applicationName ="",
    [string]$version = "7.0.6"

$updatedVersion = ""
$sevenZip = "C:Program Files7-Zip7z.exe"

#Pad the DNN Verison number with zeros
$version.Split(".") | ForEach {
    if($_ -lt 10) {
        $updatedVersion = $updatedVersion + "0" + $_ + "."
    else {
        $updatedVersion = $updatedVersion + "0" + $_ + "."

$updatedVersion = $updatedVersion.TrimEnd('.')

if($applicationName -ne "")
    #Create Database
    $srv= new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")
    $db = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Database -argumentlist $srv, $applicationName

    #Create Directory
    New-Item -ItemType directory -Path I:wwwroot$applicationNameWebsite

    #Create IIS Application
    New-Item IIS:SitesDefault$applicationName -type Application  -physicalPath I:wwwroot$applicationNameWebsite

    #Unzip DNN Version
    $zipPath = "I:SoftwareDNN$versionDotNetNuke_Community_" + $updatedVersion + "_Install.zip"
    $zipArgs = "x", $zipPath,"-oI:wwwroot$applicationNameWebsite"
	& $sevenZip $zipArgs

    #Launch Web Browser.
    Start-Process -FilePath "http://localhost/$applicationName"



There are a few assumptions that are made in this script that you can modify if you wish.

  1. Version input format 7.0.6 matches a folder folder structure where you save your DNN installs
  2. You have a repository of downloaded DNN installs.
  3. Your default IIS instance is called Default. See line 32 if you wish to change it to Default Web Site
  4. The database you’re installing is on localhost. See line 24 if you wish to change that.
  5. You have SevenZip to unzip the packages.
Jonathan Sheely

Sr Software Engineer at Maxiom Technology. Jonathan is an out of the box thinker who has over 10 years experience building and supporting web application software and infrastructure. Jon specializes in ASP.NET C#, Javascript and CSS but is willing to learn anything that gets the job done.

1 Comment