Office 365 Create A New Group In SharePoint Online using PowerShell

#######################################
# Create a SharePoint Group in a SharePoint Online Site using PowerShell O365
# Required Parameters:
# Author: Gowtham Rajamanickam
# Date:12-March-2017
########################################
  1. # create a SharePoint Group in a SharePoint Online Site   
  2. function Create-Group   
  3. {   
  4.     param ($SPonlineUrl,$Username,$Password,$GroupName,$GroupDescription)   
  5.     try   
  6.     {       
  7.          
  8.         #Adding the Client OM Assemblies           
  9.         Add-Type -Path "C:\CSOMDLL\Microsoft.SharePoint.Client.dll"   
  10.         Add-Type -Path "C:\CSOMDLL\Microsoft.SharePoint.Client.Runtime.dll"   
  11.   
  12.        #create context for connect with SharePoint online  
  13.         $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SPonlineUrl)    
  14.         $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)     
  15.         $Ctx.Credentials = $Credentials       
  16.         $RootWebSite = $Ctx.Web           
  17.         $GroupCreationInfo=New-Object Microsoft.SharePoint.Client.GroupCreationInformation   
  18.         $GroupCreationInfo.Title=$GroupToCreate   
  19.         $GroupCreationInfo.Description=$GroupToCreateDescription   
  20.         $Group=$spoRootWebSite.SiteGroups.Add($GroupCreationInfo)   
  21.         $Ctx.ExecuteQuery()   
  22.         $Ctx.Dispose()   
  23.     }   
  24.     catch [System.Exception]   
  25.     {   
  26.         write-host -f red $_.Exception.ToString()      
  27.     }       
  28. }   
  29.   
  30. #Enter the below manatory Parameters   
  31.   
  32. $SPonlineUrl = "https://gowthamr.sharepoint.com/"    
  33. $Username = "*******"     
  34. $Password=convertto-securestring "*****" -asplaintext -force   
  35. $GroupName="Gowtham_Group"   
  36. $GroupDescription="CustomGroup"   
  37.    
  38. Create-Group -sSiteColUrl $SPonlineUrl -sUsername $Username -sPassword $Password -sGroupToCreate $GroupName -sGroupToCreateDescription $GroupDescription  

Run the code given above and check your SharePoint Site. A new group is created successfully.

Was my blog helpful?

If my blog is helpful, please let us know at the bottom of this page. If it is not helpful, let us know what was confusing or missing. I’ll use your feedback to double-check the facts, add info and update this blog.
Ebook Download
View all
Learn
View all