DotNetNuke Install using PowerShell

Sample Script from DNN Blog to create a site using PowerShell.

  • Needs some work.
  • Its never been tested
  • Remember the PowerShell has to run as Administrator.
  • This script is old and was made for DNN v5.4 install.
  • You need to edit the first sections.
  • Not for production

Sample Code

#1. Choose which type of install one
#2. Edit the CD path to match your system
#3. Edit the filename to match your install

#Remove the hashtags for Professional
#cd "C:\DotNetNuke\ProReleases" #$CEorPE ="Professional"
#Filename ="DotNetNuke_Professional_5.4.0_Install.zip"
#Remove the hashtags for Community
#cd "C:\DotNetNuke\Releases" #$CEorPE ="Community"
#Filename ="DotNetNuke_Professional_5.4.0_Install.zip" $CurrentLocation=get-location

#Edit this section as needed
$version="050400"
$ZipFile = $CurrentLocation + "\" + $version + "\" + $Filename
$websiteName = "DotNetNuke" + $CEorPE + $version + "Install"
$websiteAddress = "DotNetNuke" + $CEorPE + $version + ".Install"
$dbname = "DotNetNuke" + $CEorPE + $version + "Install"
$physicalPath = "DotNetNuke" + $CEorPE + $version + "Install"

#Time to get to work
#No more editing, in theory
#Remove existing IIS Site and App pool to make a clean install
Import-Module WebAdministration
Remove-Item iis:\Sites\$websiteName -Recurse
Remove-Item IIS:\AppPools\DotNetNukeAppPool -Recurse
#Setup a command shell in the path location
$shell=new-object -com shell.application
$CurrentPath=$CurrentLocation.path
$OutPutPath = "$CurrentPath\$physicalPath"
$OutPutLocation=$shell.namespace($OutPutPath)
#Delete anything in the destination folder for a clean install
new-item —force -path $OutPutPath -itemtype "directory"
get-childitem $OutPutPath | remove-item -force -recurse

#Unzip the file to the destination $ZipFolder = $shell.namespace($ZipFile)
$OutPutLocation.Copyhere($ZipFolder.items())
#Set the ACL on the folder
$acl = Get-Acl $OutPutPath
$permission = "NETWORK SERVICE","FullControl","Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
Get-ChildItem $OutPutPath -Recurse -Force | Set-Acl -AclObject $acl
#Create the IIS Site
New-Item IIS:\AppPools\DotNetNukeAppPool -Force
Set-ItemProperty IIS:\AppPools\DotNetNukeAppPool -name ProcessModel.identityType -Value 2
New-Item iis:\Sites\$websiteName -bindings @{protocol="http";bindingInformation=":80:$websiteAddress"} -physicalPath $OutPutPath
Set-ItemProperty IIS:\Sites\$websiteName -name applicationPool -value DotNetNukeAppPool
#Update the hosts file
$hostsentry = Select-String $Env:SystemRoot\System32\drivers\etc\hosts -pattern "$websiteAddress" -quiet
if (-not $hostsentry)
{
    Add-Content $Env:SystemRoot\System32\drivers\etc\hosts "127.0.0.1        $websiteAddress"
}

PowerShell is a multi-threaded applications so you need to wait before opening IE and test the site.  You can add this to the end of your script to do the waiting

#Now open IE and navigate to the site 
$ie = new-object -com "InternetExplorer.Application"
$ie.Visible = $true $wait = $true
  $numWaits = 0
  while ($wait -and $numWaits -lt 100) {
    $numWaits++
    [System.Threading.Thread]::Sleep(500)
  $doc = $ie.Document
    if ($doc -ne $null) {
      $wait = $false
    }
    else {
      write-host "Waiting for app to respond $numWaits . . ."
    }
  }
  if ($numWaits -eq 100) {
    throw "Application did not respond after 100 delays"
  }
  else {
    write-host "Application has responded"
  }
$auto = $doc.getElementByID("wizInstall_rblInstall_2")
$auto.checked = $true
$nextBtn = $doc.getElementByID("wizInstall_StartNavigationTemplateContainerID_StartNextLinkButton")
$nextBtn.click()
[System.Threading.Thread]::Sleep(60000)
$ie.Navigate("http://$websiteAddress/")

References

Did you get a clue?

If you got a clue and want to thank me, then visit the thank me page. It’s the best way to keep me publishing articles and keeping this site operation.

This site uses affiliate links. When you go to another site from here the link typically will have an affiliate code attached to it. Your actions on that site may earn a small commission for me. Read our affiliate link policy for more details.

{fin}

Scroll to Top