Reputation: 125
I have security groups created on office 365 and I also have groups on my sharepoint site. I want to add security group which is on o365 to sharepoint site group programmatically.
Could you please help me?
Thank you
Upvotes: 0
Views: 6222
Reputation: 125
public Group createSharepointGroup(string Name, string description)
{
try
{
GroupCreationInformation groupInfo = new GroupCreationInformation();
groupInfo.Description = description;
groupInfo.Title = Name;
Group group = currentWeb.SiteGroups.Add(groupInfo);
clientContext.Load(group);
clientContext.ExecuteQuery();
return group;
}
catch (Exception ex)
{
MessageBox.Show(ex.InnerException.ToString());
return null;
}
}
Upvotes: 0
Reputation: 14336
The answer depends on what platform you want to do this programatically with. I'm assuming you're using PowerShell, in which case your best bet is the Add-SPOUser
cmdlet, which "Adds an existing Office 365 user or an Office 365 security group to a SharePoint group."
The example below assumes you're using PowerShell:
$SecGroupName = "TestSecurityGroup" # The security group DisplayName
$SPOGroupName = "TestSharePointGroup" # The SharePoint Online group
# Get the SharePoint site
$SPOSite = Get-SPOSite "https://contoso.sharepoint.com"
# Add the security group as a member of the SharePoint Online group
Add-SPOUser -Site $SPOSite -LoginName $SecGroupName -Group $SPOGroupName
Some links you might find usefull:
(Note that users and groups in Office 365 are actually Azure Active Directory users and security groups, which is why I provide links to the Azure AD PowerShell cmdlets.)
Upvotes: 2