Skip to content

Instantly share code, notes, and snippets.

View AsishP's full-sized avatar

Asish Padhy AsishP

  • Sydney, Australia
View GitHub Profile
Connect-SPOService "https://[tenant]-admin.sharepoint.com"
Connect-PnPOnline "[siteurl]"
Set-SPOSite "[siteurl]" -DenyAddAndCustomizePages 0
Set-PnPPropertyBagValue -Key "[propertyName]" -Value "[propertyValue]" -Indexed
Set-SPOSite "[siteurl]" -DenyAddAndCustomizePages 1
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using OfficeDevPnP.Core;
using OfficeDevPnP.Core.Framework.Graph;
using OfficeDevPnP.Core.Pages;
const string authString = "https://login.microsoftonline.com/<tenant domain>/";
const string clientId = "<Graph App ID>";
const string clientSecret = "<Graph App Secret>";
var authenticationContext = new AuthenticationContext(authString, false);
ClientCredential clientCred = new ClientCredential(clientId, clientSecret);
var group = UnifiedGroupsUtility.ListUnifiedGroups(token, mailNickname: url).Where(result => result.MailNickname.ToLower().Equals(alias.ToLower())).First();
// We received a group entity containing information about the group
string groupurl = group.SiteUrl;
string groupId = group.GroupId;
string mailNickName = group.MailNickname;
const string spTenantUrl = "https://<tenantname>-admin.sharepoint.com/";
using (var contextTenant = new ClientContext(spTenantUrl))
{
contextTenant.Credentials = new SharePointOnlineCredentials(userName, secpass);
Tenant tSP = new Tenant(contextTenant);
tSP.SetSiteAdmin(groupurl, userName, true);
contextTenant.ExecuteQuery();
}
{
"http": {
"routePrefix": "api",
"maxOutstandingRequests": -1,
"maxConcurrentRequests": 1,
"dynamicThrottlesEnabled": false
}
}
UnifiedGroupsUtility.UpdateUnifiedGroup(group.GroupId, token, groupLogo: <logo url>,
members:<Members email array>, isPrivate: <boolean>, retryCount: <numberofretries>);
return processComplete
? req.CreateResponse(HttpStatusCode.OK, "Success")
: req.CreateResponse(HttpStatusCode.Accepted, "Error");
using (var context = new ClientContext(<siteURL>))
{
contextAsset.Credentials = new SharePointOnlineCredentials(UserName, SecurePass);
Web web = contextAsset.Web;
contextAsset.Load(web, w => w.Navigation);
contextAsset.Load(web);
contextAsset.ExecuteQuery();
//Start working on Navigation
NavigationNodeCollection lefthandNav = web.Navigation.QuickLaunch;
//Check the gist code - https://gist.github.com/AsishP/b817455ce58b753e4f02ae5a0482e7a4 for filling the NavIds Array
foreach (int id in navIds)
{
NavigationNode nodeToDelete = web.Navigation.GetNodeById(id);
contextAsset.Load(nodeToDelete);
contextAsset.ExecuteQuery();
nodeToDelete.DeleteObject();
contextAsset.ExecuteQuery();
}
using (var contextNavigation = new ClientContext(<siteURL>))
{
contextNavigation.Credentials = new SharePointOnlineCredentials(UserName, SecurePass);
Web web = contextNavigation.Web;
contextNavigation.Load(web, w => w.Navigation);
contextNavigation.Load(web);
contextNavigation.ExecuteQuery();
//Start working on Navigation
NavigationNodeCollection lefthandNav = web.Navigation.QuickLaunch;