Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
chrisobriensp / Office365GroupCreatorThroughPnP_Complete.ps1
Created June 18, 2018 11:04
Uses PnP PowerShell to create an Office 365 Group (using an AAD app for Graph authentication) - completed.
Write-Output "COB-O365-Group-VSCode: PowerShell Timer trigger function executed at:$(get-date)";
$currentDate = Get-Date -Format "ddd_dd_MM_hh_mm"
$groupPrefix = "COB_AutoCreatedGroup___"
$groupName = $groupPrefix + $currentDate
Write-Output "Will attempt to create group with name '$($groupName)'"
$appid = $env:AppID
$client_secret = $env:AppSecret
@chrisobriensp
chrisobriensp / Office365GroupCreatorThroughPnP.ps1
Created June 11, 2018 19:44
Uses PnP PowerShell to create an Office 365 Group (using an AAD app for Graph authentication)
Write-Output "COB-O365-Group-Creator: PowerShell function executed at:$(get-date)"
$appid = "[TODO - ENTER YOUR APP ID HERE]"
$client_secret = "[TODO - ENTER YOUR APP SECRET KEY HERE]"
$tenant = "[TODO - ENTER YOUR TENANT PREFIX HERE].onmicrosoft.com"
$currentDate = Get-Date -Format "ddd_dd_MM"
$groupPrefix = "COB_AutoCreatedGroup___"
$groupName = $groupPrefix + $currentDate
@chrisobriensp
chrisobriensp / COB_AppInsights_TrackSiteCreation.cs
Created September 15, 2017 15:18
Uses Azure App Insights to track site collection creation in SharePoint Online.
ClientContext adminSiteContext = new ClientContext(TENANT_ADMIN_URL);
adminSiteContext.Credentials = new SharePointOnlineCredentials(TENANT_ADMIN_USER, securePwd);
Web templateWeb = adminSiteContext.Web;
adminSiteContext.Load(templateWeb, w => w.Title, w => w.Url);
adminSiteContext.ExecuteQueryRetry();
Console.WriteLine("Auth'd to site: " + templateWeb.Url);
// create new site collection..
Tenant tenant = new Tenant(adminSiteContext);
@chrisobriensp
chrisobriensp / COB_AppInsights_TrackSiteProvisioning.cs
Created September 15, 2017 15:06
Uses Azure App Insights to track site provisioning and applying a PnP template
XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(TEMPLATE_FILE_PATH, string.Empty);
ProvisioningTemplate template = provider.GetTemplate(TEMPLATE_FILE);
stopwatch = System.Diagnostics.Stopwatch.StartNew();
try
{
rootWeb.ApplyProvisioningTemplate(template);
stopwatch.Stop();
@chrisobriensp
chrisobriensp / PnPTemplateWithSPFxExtension.xml
Created September 11, 2017 12:43
An extract of PnP template XML, which associates a tenant-scoped SPFx extension to the web being provisioned.
<pnp:CustomActions>
<pnp:WebCustomActions>
<pnp:CustomAction Name="COB-SPFx-GlobalHeader"
Description="Adds a global header to the site"
Location="ClientSideExtension.ApplicationCustomizer"
Title="COB-SPFx-GlobalHeader"
ClientSideComponentId="[YOUR GUID HERE]"
Sequence="0"
Rights=""
RegistrationType="None" />
@chrisobriensp
chrisobriensp / ManageSPFxExtension_Methods.cs
Last active September 7, 2017 13:56
C# code to add/remove/list globally-deployed SPFx extensions (with skipFeatureDeployment=true), specifically Application Customizers, using OfficeDevPnP.Core
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using OfficeDevPnP.Core.Entities;
using System;
using System.Linq;
namespace COB.SPFx.Extensions.Manage
{
/// <summary>
/// Console app code to add/remove/list SPFx Application Customizer extensions..
@chrisobriensp
chrisobriensp / RegisterSPFxExtensionToSelectedSites.ps1
Last active February 17, 2021 06:23
PowerShell script to add/remove/list a globally-deployed SPFx extension (with skipFeatureDeployment=true), to selected sites/webs, specifically Application Customizers. Uses OfficeDevPnP PowerShell.
$credentials = Get-Credential
# details of sites
[string[]] $sitesToProcess =
"https://chrisobriensp.sharepoint.com/sites/team1",
"https://chrisobriensp.sharepoint.com/sites/team2",
"https://chrisobriensp.sharepoint.com/sites/team3",
"https://chrisobriensp.sharepoint.com/sites/team4"
# details of custom action/SPFx extension
@chrisobriensp
chrisobriensp / SPFx_AddTiming_GraphCall2.ts
Created August 24, 2017 16:57
Uses Azure App Insights to track that a call to the Graph has occurred (and the duration).
private loadUpcomingMeetings(): void {
this.setState((previousState: IUpcomingMeetingsState, props: IUpcomingMeetingsProps): IUpcomingMeetingsState => {
previousState.loading = true;
return previousState;
});
this.getGraphAccessToken()
.then((accessToken: string): Promise<IMeeting[]> => {
// start timer here..
this._startTime = new Date();
@chrisobriensp
chrisobriensp / SPFx_AddTiming_GraphCall.ts
Created August 19, 2017 21:43
Uses Azure App Insights to track that a call to the Graph has occurred (and the duration).
// start timer here..
this._startTime = new Date();
this.props.context.graphHttpClient.get(`v1.0/groups/${groupId}/events`, GraphHttpClient.configurations.v1).then((response: HttpClientResponse) => {
if (response.ok) {
return response.json();
} else {
console.warn(response.statusText);
}
}).then((result: any) => {
AppInsights.trackPageView(
document.title, /* (optional) page name */
window.location.pathname, /* (optional) page url if available */
{
userLogin: this.context.pageContext.user.loginName,
userDisplayName: this.context.pageContext.user.displayName,
isExternalGuest: this.context.pageContext.user.isExternalGuestUser
}, /* (optional) dimension dictionary */
{ }, /* (optional) metric dictionary */
0 /* page view duration in milliseconds */