Create sequential SharePoint sites with Power Automate

Have you ever wanted to create SharePoint sites with following numbers in the URL? Maybe you need quick testing on dozen of sites, or maybe it’s simply your naming convention. Who knows! 😉

In today’s post, we’ll use Power Automate to create our SharePoint sites where the naming convention will have 001, 002, […] at the end of the URL and up to a certain number of sites. Let’s go!

Variables

Let’s set a Compose action and a variable first.

The Compose action will contain a value that will not change in the flow but offers greater performance compared to variables.

  • SiteTest Root URL: This will be our “root” URL where we’ll add the numbers at the end
  • Initialize varSiteNumber: This is the starting point for our numbering. The value int(000) will be excluded because we won’t name a site “SiteTest000”. It doesn’t make sense 😅

Make sure to cast the value 000 into an int() function. The flow will fail if you don’t because it’ll be considered a string, and we need to compare it in the next steps.

Condition

Now let’s add a condition to only build sites up to a certain number. What we’re going to do:

  • Compare if the varSiteNumber is lower than our target number
  • Repeat the site creation appending the number in the URL until we reach our target SharePoint site

In the condition, if the varSiteNumber is less than int(3), go do something otherwise don’t do anything (in my case). You can change the number 3 to how many SharePoint sites you wish to create. This number will be included, meaning we’ll have a SiteTest003.

We’ll use a Do until action and set the loops to varSiteNumber is equal to int(3). Once the loop has started, we need to increment the variable by 1 from our starting point which was int(000). At this point, we’re using numbers.

But in the next step, we’re formatting that new number into a string because for our scenario, we need the leading zeros. So we use the formatNumber() function feeding our previous action.

If we run the flow now, this is output we get 🙂

Our last two actions will be to create the SharePoint site using the Send an HTTP request to SharePoint and making sure we set the varSiteNumber to the new number for the (potential) next loop.

The outputs in the request body are as follows:

 "Title": "Site Test @{outputs('Reformat_to_string_to_get_the_leading_zeros')}"
"Url":"@{outputs('SiteTest_Root_URL')}@{outputs('Reformat_to_string_to_get_the_leading_zeros')}"

Run the flow

If your flow runs successfully, the number of sites in your int() logic should be created.

Thanks for reading! 🙂

Discover more from Veronique's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading