#######################################
# Create a SharePoint Group in a SharePoint Online Site using PowerShell O365
# Required Parameters:
# Author: Gowtham Rajamanickam
# Date:12-March-2017
########################################
- # create a SharePoint Group in a SharePoint Online Site
- function Create-Group
- {
- param ($SPonlineUrl,$Username,$Password,$GroupName,$GroupDescription)
- try
- {
-
- #Adding the Client OM Assemblies
- Add-Type -Path "C:\CSOMDLL\Microsoft.SharePoint.Client.dll"
- Add-Type -Path "C:\CSOMDLL\Microsoft.SharePoint.Client.Runtime.dll"
-
- #create context for connect with SharePoint online
- $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SPonlineUrl)
- $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)
- $Ctx.Credentials = $Credentials
- $RootWebSite = $Ctx.Web
- $GroupCreationInfo=New-Object Microsoft.SharePoint.Client.GroupCreationInformation
- $GroupCreationInfo.Title=$GroupToCreate
- $GroupCreationInfo.Description=$GroupToCreateDescription
- $Group=$spoRootWebSite.SiteGroups.Add($GroupCreationInfo)
- $Ctx.ExecuteQuery()
- $Ctx.Dispose()
- }
- catch [System.Exception]
- {
- write-host -f red $_.Exception.ToString()
- }
- }
-
- #Enter the below manatory Parameters
-
- $SPonlineUrl = "https://gowthamr.sharepoint.com/"
- $Username = "*******"
- $Password=convertto-securestring "*****" -asplaintext -force
- $GroupName="Gowtham_Group"
- $GroupDescription="CustomGroup"
-
- 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.