DEV Community

Kevin Jump
Kevin Jump

Posted on

Umbraco Setup/teardown PowerShell scripts.

Umbraco 9 embraces dotnet core and all the goodness that brings; This includes creating your umbraco site from the command line:

dotnet new umbraco -n myUmbracoSite
Enter fullscreen mode Exit fullscreen mode

which is super cool, and after some intial setup screens you will have your new Umbraco site up and running locally.

How fast can you go?

So a while back this meant I got into invented a whole Umbraco speed run challenge.

And it resulted in me writing some PowerShell scripts that allow me to setup and tear down Umbraco sites really quickly (around 30-40 seconds).

Now I have shared these scripts before, but I've updated them a bit since then and I need to update what they do.

gist script is here


The Setup

If you save that file somewhere on your computer. You can then import this module into your powershell command line.

Import-Module -Name C:\Source\Tools\umbraco-tools.psm1
Enter fullscreen mode Exit fullscreen mode

If you place that line in your profile.ps1 file (usually documents\powershell\profile.ps1) it will be avalible everytime you start up a terminal.

For unattended install to work, you need to create three environmental variables on your PC

UMB_USER
UMB_EMAIL
UMB_PASSWORD


The commands

With the script installed you get three new commands.

new-umbraco  // create an new umbraco site
remove-umbraco // remove an umbraco site (and the db)
clear-umbracodbs // remove all dbs 
Enter fullscreen mode Exit fullscreen mode

> New-Umbraco

Creates a new umbraco site installs packages, and sets up unattended installtion (so you don't have to do the setup afterwards)

New-Umbraco <SITE_NAME> [options]

-n name        name of the project
-p package     list of packages to install
-f framework   framework to use (default .net5)
-nostarter     don't install the starter kit package 
-donotrun      don't immediately run the site when complete
-prerelease    fetch pre-release versions of any packages we ask for
Enter fullscreen mode Exit fullscreen mode

For Example:
I do this quite often when testing: Create a new site, don't install the starter kit, install uSync package and open the site in VsCode when you have finished.

New-Umbraco MyNewSite -noStarter -packages uSync -code
Enter fullscreen mode Exit fullscreen mode

Usually this is super fast and I can start work right away.

> Remove-Umbraco

Remove an Umbraco installation from disk and remove the db.

Remove-Umbraco <SITE-NAME> -RemoveFolder

-n name          name of site
-RemoveFolder    also delete the folder for the umbraco site
Enter fullscreen mode Exit fullscreen mode

> Clear-UmbracoDbs

through the scripts all umbraco databaswes are created with an umb- prefix, so the Clear-UmbracoDbs command simply removes all these dbs from your local instance, good if you know you've just created a load of trash dbs you need to get rid off.

Top comments (2)

Collapse
 
rsoeteman profile image
rsoeteman

Hi Kevin,

Realy cool example how to use Powershell and .net CLI to create Umbraco sites. I am using this as well to setup testsites for my products, really fast now. Last week I found out it was really easy to use LocalDB for new sites as well.

dotnet new umbraco -n $sitename --connection-string "Server=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Umbraco.mdf;Integrated Security=true"

Reading your GIST reminds me, Need to learn more PowerShell :-) #h5yr

Collapse
 
kevinjump profile image
Kevin Jump

yeah - i think this ended up using SQL for the speed (i was speed running!) so on my pc its 10/15 seconds faster to use SQL. but for anything i want to be portable im using LocalDB