Office 365 – PowerShell Script – Add custom site design to the O365 tenant using PnP on behalf of Azure App (using Azure App credentials)

Hi All,

In one of my previous article “Office 365 – PowerShell script to add / create custom site design to our Tenant” we discussed regarding adding site design to O365 tenant using PowerShell script.

For more details about Site Designs and Site scripts please refer SharePoint site design and site script overview

In that article we connected O365 tenant using user credential where user has “Global Admin” rights. Now we have case like we don’t have user who have “Global Admin” rights. But we have azure app created which having rights on whole tenant.

Please refer my two following articles for creating an azure app and giving rights to tenant. 

Office 365 – Azure Active Directory – Registering/Creating new Azure App – detailed steps

Office 365 – Microsoft Graph – Part 2 – Granting permission to Azure Apps to use Microsoft Graph APIs using CSOM Here, we now we will discuss how connect O365 using azure appid and client secret key and add new site design to O365 tenant. We will use PnP PowerShell cmdlets.

Following are the detailed steps:

  • Connect to O365 / SharePoint Online – using Azure AppId and App client secret key. Here please notice that we are not using any user.
  • Once we connected O365, we are ready to add custom site design. For adding site design, we need site script. [Site scripts are JSON files which specify an ordered list of actions which are executed when we create new site.] We will get script content by using Get-Content script
  • Once we have site script content, we are ready to add script  

This command will return Site Script ID as, this ID can be used while adding site design / executing cmdlet of site design

Id                                                                       Title                 Version Content

45116cea-2abb-4cf9-98da-ecd131cdf55c <Script Title> 0

  • Once we have site script ID, we are ready to add site design as

Here, web template 68 is for communication site. (Just for reference – Web Template for Modern Team site with group is 64 and web template for Modern Team site without group is 1.)  Here, site design is based on communication site. If command executed successfully we will get Site Design ID as

Id                                                                         Title                                 Site Scripts 5fde7e54-0e84-4977-859d-73af3846e8cc  <Site design Title>       {45116cea-2abb-4cf9-98da-ecd131cdf55c}

Complete Scripts:

References:

  1. Connect-PnPOnline
  2. PnP PowerShell overview
  3. Office 365 – PowerShell script to add / create custom site design to our Tenant
  4. Office 365 – Azure Active Directory – Registering/Creating new Azure App – detailed steps
  5. Office 365 – Microsoft Graph – Part 2 – Granting permission to Azure Apps to use Microsoft Graph APIs using CSOM
  6. SharePoint site design and site script overview
  7. Get-Content
  8. Add-PnPSiteScript
  9. Add-SPOSiteDesign

Thanks for reading 😊

Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.

Stay tuned on Knowledge-Junction, will come up with more such articles.

Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.