Skip to content

Instantly share code, notes, and snippets.

View gautamdsheth's full-sized avatar
:shipit:
Shipping

Gautam Sheth gautamdsheth

:shipit:
Shipping
View GitHub Profile
$PnPPowerShellAppId = "31359c7f-bd7e-475c-86db-fdb8c937548e"
# Connect to you Azure AD, use Global admin or equivalent account
Connect-AzAccount
# get graph access token for current user --need Global admin
$accessTokenInformation = Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com"
$token = $accessTokenInformation.Token
# Create a new service prinicpal
AllSites.FullControl
User.Read.All
TermStore.ReadWrite.All
ServiceHealth.Read
ActivityFeed.Read
Team.Create
TeamsAppInstallation.ReadWriteForUser
ChannelMember.ReadWrite.All
TeamMember.ReadWrite.All
TeamSettings.ReadWrite.All
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using Newtonsoft.Json.Linq;
using OfficeDevPnP.Core;
using OfficeDevPnP.Core.Framework.Provisioning.Model.Configuration;
using OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers;
using OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
$tenant = "tenant.onmicrosoft.com"
# Create Azure AD app
$psa = Initialize-PnPPowerShellAuthentication -ApplicationName TestTeamsApp -Tenant $tenant -Store CurrentUser
# Connect to SPO+Graph using certificate authentication
Connect-PnPOnline "https://tenant-admin.sharepoint.com/" -Tenant $tenant -ClientId $psa.AzureAppId
-Thumbprint $psa.'Certificate Thumbprint'
# Store the extracted template somwhere
Get-PnPTenantTemplate -Out "TeamTemplate.xml" -Configuration "ExtractTeam.json"
{
"$schema": "https://aka.ms/sppnp-extract-configuration-schema",
"tenant": {
"teams": {
"teamSiteUrls": ["https://your-tenant-name.sharepoint.com/sites/HRTeam"],
"includeGroupId": false,
"includeMessages": false
}
},
"handlers": [
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using Newtonsoft.Json.Linq;
using OfficeDevPnP.Core;
using OfficeDevPnP.Core.Framework.Provisioning.Connectors;
using OfficeDevPnP.Core.Framework.Provisioning.Model;
using OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers;
using OfficeDevPnP.Core.Framework.Provisioning.Providers;
using OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml;
using System;
Connect-PnPOnline "https://<tenant-name>.sharepoint.com/" -Scopes "User.ReadWrite.All"
Apply-PnPTenantTemplate -Path .\AddAzureADUser.xml
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2019/09/ProvisioningSchema"
Author="Blade runner"
Generator="Human being ?"
Version="1.0"
Description="A sample Provisioning document"
DisplayName="Sample Provisioning"
ImagePreviewUrl="https://sharepointpnp.com/ImagePreview.png">
<pnp:Preferences Author="Blade runner" Version="1.0" Generator="Human being, am I ?">
<pnp:Parameters>
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
AuthenticationManager authenticationManager = new AuthenticationManager();
using (ClientContext clientContext = authenticationManager.GetSharePointOnlineAuthenticatedContextTenant("https://tenant-admin.sharepoint.com/", "userName", "password"))
{
var tenant = new Tenant(clientContext);
Connect-PnPOnline "https://<tenant>-admin.sharepoint.com"
Apply-PnPTenantTemplate -Path .\PnPUserProfileTemplate.xml