#######################################
# 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. #Adding the Client OM Assemblies
  8. Add-Type -Path "C:\CSOMDLL\Microsoft.SharePoint.Client.dll"
  9. Add-Type -Path "C:\CSOMDLL\Microsoft.SharePoint.Client.Runtime.dll"
  10. #create context for connect with SharePoint online
  11. $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SPonlineUrl)
  12. $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)
  13. $Ctx.Credentials = $Credentials
  14. $RootWebSite = $Ctx.Web
  15. $GroupCreationInfo=New-Object Microsoft.SharePoint.Client.GroupCreationInformation
  16. $GroupCreationInfo.Title=$GroupToCreate
  17. $GroupCreationInfo.Description=$GroupToCreateDescription
  18. $Group=$spoRootWebSite.SiteGroups.Add($GroupCreationInfo)
  19. $Ctx.ExecuteQuery()
  20. $Ctx.Dispose()
  21. }
  22. catch [System.Exception]
  23. {
  24. write-host -f red $_.Exception.ToString()
  25. }
  26. }
  27. #Enter the below manatory Parameters
  28. $SPonlineUrl = "https://gowthamr.sharepoint.com/"
  29. $Username = "*******"
  30. $Password=convertto-securestring "*****" -asplaintext -force
  31. $GroupName="Gowtham_Group"
  32. $GroupDescription="CustomGroup"
  33. 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.