Microsoft 365 – SharePoint Online – Creating new SharePoint group using PnP PowerShell

Microsoft 365 - SharePoint online - PowerShell script to create new SharePoint custom group using PnP PowerShell CMDLET - New-PnPSiteGroup
Microsoft 365 - SharePoint online - PowerShell script to create new SharePoint custom group using PnP PowerShell CMDLET - New-PnPSiteGroup

Hi All,

Greetings for the day!!

Today sharing PnP PowerShell CMDLET for creating SharePoint group which I used in one of the SharePoint online project

SharePoint group

  • A SharePoint group is collection / set of users
  • SharePoint group allows us to manage these set of users rather individual users

Details / Background / Usecase

  • We are creating multiple site collections using PnP site provisioning engine
  • We have created our custom template and using it for creating new site collections
  • One of our requirement is to have our custom SharePoint group
  • While applying template I noticed that for some reason, for some sites creating custom group is failing
  • Though its in template which we generated
  • So thought to create explicitly after template is applied successfully and so here is the article

Previously I already have an article – how to create SharePoint group in modern site collection using PowerShell – Microsoft 365 : SharePoint Online – PowerShell script – PowerShell script to create SharePoint group in a given site collection

In this article we will discuss – how to create SharePoint group in modern SharePoint online sites using PnP PowerShell

STEPS to create Group in SharePoint Online modern communication site using PnP PowerShell

  • Connects PnP online using – Connect-PnPOnline
  • Connect to the the site where we need to create our custom group
  • Here we will be creating our custom group “KnowledgeJunction Distributors” in my local tenant, on root site – https://knowledgejunction1.sharepoint.com
  • Before executing or moving ahead, currently groups available on my root site are as
fig : Microsoft 365 - SharePoint online - modern communication site - OOB groups available - before creating new custom group
fig : Microsoft 365 – SharePoint online – modern communication site – OOB groups available – before creating new custom group

Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com

  • Once we successfully connected to SharePoint Online / PnP Online, next step is use the PowerShell CMDLET to create new group – New-PnPSiteGroup
  • Syntax for New-PnPSiteGroup

New-PnPSiteGroup
   -Name <String>
   -PermissionLevels <String[]>
   [-Site <SitePipeBind>]

Where,

–Name: group name

–PermissionLevels – Permission levels to grant the newly created group.

fig : Microsoft 365 - SharePoint online - OOB permissions levels
fig : Microsoft 365 - SharePoint online - PnP CMDLET to create new SharePoint group - New-PnPSiteGroup
fig : Microsoft 365 – SharePoint online – PnP CMDLET to create new SharePoint group – New-PnPSiteGroup

New-PnPSiteGroup -Site https://knowledgejunction1.sharepoint.com -Name "KnowledgeJunction Distributors" -PermissionLevels "Full Control"

fig : Microsoft 365 - SharePoint online - successfully created new SharePoint group using PnP CMDLET - New-PnPSiteGroup
fig : Microsoft 365 – SharePoint online – successfully created new SharePoint group using PnP CMDLET – New-PnPSiteGroup
  • After successfully execution of “New-PnPSiteGroup” CMDLET we have our new custom group is in place as
fig : Microsoft 365 - SharePoint online - successfully created new SharePoint group using PnP CMDLET - New-PnPSiteGroup
fig : Microsoft 365 – SharePoint online – successfully created new SharePoint group using PnP CMDLET – New-PnPSiteGroup

Complete Script

PS C:\> Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com

WARNING: 
A newer version of PnP PowerShell is available: 2.2.0.

Use 'Update-Module -Name PnP.PowerShell' to update.
Use 'Get-PnPChangeLog -Release 2.2.0' to list changes.

You can turn this check off by setting the 'PNPPOWERSHELL_UPDATECHECK' environment variable to 'Off'.


PS C:\> New-PnPSiteGroup -Site https://knowledgejunction1.sharepoint.com -Name "KnowledgeJunction Distributors" -PermissionLevels "Full Control"


LoginName      : KnowledgeJunction Distributors
Title          : KnowledgeJunction Distributors
OwnerLoginName : prasham@knowledgejunction1.onmicrosoft.com
OwnerTitle     : Prasham Sabadra
Users          : {}
Roles          : {Full Control}


fig : Microsoft 365 - SharePoint online - PowerShell script to create new SharePoint custom group using PnP PowerShell CMDLET - New-PnPSiteGroup
fig : Microsoft 365 – SharePoint online – PowerShell script to create new SharePoint custom group using PnP PowerShell CMDLET – New-PnPSiteGroup

REFERENCES

Thanks for reading !!! HAVE a FANTASTIC LEARNING AHEAD 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

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