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
Add-Type -Path (Resolve-Path "$env:CommonProgramFiles\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "$env:CommonProgramFiles\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll")
#Site collection URL
$siteurl = "https://tenantname.sharepoint.com/sites/testsitecollection"
$userName ="user.name@tenantname.com"
$password ="password"
#client context object and setting the credentials
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": [
@gautamdsheth
gautamdsheth / InstallAppCSOM.cs
Last active June 20, 2020 19:15
Install app to site collection using CSOM C# in SharePoint Online
string webUrl = "https://tenant-name.sharepoint.com/sites/test/";
string username = "user.name@tenantname.onmicrosoft.com";
string password = "password";
SecureString secureString = new SecureString();
password.ToList().ForEach(secureString.AppendChar);
var credentials = new SharePointOnlineCredentials(username, secureString);
using (ClientContext ctx = new ClientContext(webUrl))
{
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>