Forum Discussion
Programmatically creation of Office 365 Groups
- Aug 25, 2017
You are one lazy.... ;)
Tenant tenant = new Tenant(clientContext);
var site = tenant.GetSitePropertiesByUrl(siteUrl, false);
clientContext.Load(site, s => s.Status);
site.Context.ExecuteQueryRetry();
var status = site.Status;
If I grab the access token returned from PnP PowerShell using Connect-PnPMicrosoftGraph -Scopes "Group.ReadWrite.All","User.Read.All" and use this in the same code, it works just fine. So, the Graph can do it, if the access token contains the correct permissions.
PnP PowerShell requires the two mentioned application permissions, but it also presents some delegated permissions in the consent dialog, so I'm not sure which permissions are requested during this consent approach.
I have a PR in place which is merged to support app-only tokens in the PnP commandlet. Using app-only tokens is also supported for creating Groups (https://developer.microsoft.com/en-us/graph/docs/overview/release_notes#groups).
The commandlet has this added signature.
Connect-PnPMicrosoftGraph -AppId <id> -AppSecret <secret> -AADDomain yourtenant.onmicrosoft.com
The sample to set up and consent to the app can found in the PnP dev branch at: https://github.com/SharePoint/PnP-PowerShell/tree/dev/Samples/Graph.ConnectUsingAppPermissions
You need User.Read.All and Groups.ReadWrite.All scopes in your app for this to work.