Skip to content

Instantly share code, notes, and snippets.

View phillipharding's full-sized avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / Renew Expired SharePoint ACS ClientSecret.ps1
Last active October 26, 2022 11:04
Renews an Expired ClientSecret for a Sharepoint Addin/ACS App Registration
<#
Renew An Expired Clientsecret For A Sharepoint Addin/ACS App Registration
WHEN A SHAREPOINT ADDIN/ACS APP REGISTRATION IS CREATED THE CLIENTSECRET IS SET TO EXPIRE IN 1 YEAR
THIS SCRIPT WILL RENEW AN EXPIRED CLIENTSECRET WITH A VALUE THAT EXPIRES IN 3 YEARS
.\msol-renewsharepointaddinsecret.ps1 -clientId "" -userName "" -userPassword ""
#>
param (
@phillipharding
phillipharding / SP.MoveCopyUtil.CopyFileByPath.md
Last active July 18, 2022 14:18
SP.MoveCopyUtil.CopyFileByPath()
@phillipharding
phillipharding / camlify-filter-expressions.js
Created September 6, 2021 11:37
Camlify Filter Expressions
console.clear();
const isEmptyString = (s) => { return (typeof s === "undefined") || (s === null) || (s.length < 1); };
camlCompareOp = "Or";
camlPredicate = "Contains";
options = {};
options.queryByUniqueIdentifier = "90911";
//options.queryByPayrollNumber = "90919";
//options.queryByLocation = "01-001";
@phillipharding
phillipharding / Add and Enumerate List Folder PropertyBag Values.ts
Last active February 18, 2021 16:51
Add/Set and List PropertyBag Values for a List Folder
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { spPost, SharePointQueryable } from '@pnp/sp';
import { sp } from "@pnp/sp/presets/all";
const getBody = (siteid, webid, listid, folderid, propertyName, propertyValue) => `
<Request AddExpandoFieldTypeSuffix="true" ApplicationName=".NET Library" LibraryVersion="16.0.0.0" SchemaVersion="15.0.0.0" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009">
<Actions>
<Method Id="62" Name="SetFieldValue" ObjectPathId="59">
@phillipharding
phillipharding / SharePoint PnPJS Parallel ListItem Update with Retry v2
Last active February 14, 2021 14:19
Better version of updating a SharePoint listitem in parallel using PnPJS with retry capability if error 409 (item has been updated by another user or process) occurs
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { sp } from "@pnp/sp/presets/all";
( async () => {
console.clear();
const itemId = 89;
const RetryHttpCall = async (fnToCall: () => Promise<any>, label: string, maxTryCount: number): Promise<any> => {
@phillipharding
phillipharding / SharePoint PnPJS Parallel ListItem Update with Retry
Last active February 14, 2021 13:44
Updates a SharePoint listitem in parallel using PnPJS with retry capability if error 409 (item has been updated by another user or process) occurs
/*
Hit 'ctrl + d' or 'cmd + d' to run the code, view console for results
*/
import { sp } from "@pnp/sp/presets/all";
( async () => {
console.clear();
const itemId = 89;
const RetryHttpCall = async (fnToCall: () => Promise<any>, label: string, delayStart: number, maxTryCount: number): Promise<any> => {
@phillipharding
phillipharding / body.json
Created October 17, 2020 15:38 — forked from garrytrinder/m365-identity.sh
Create custom Azure AD identity for use with CLI for Microsoft 365 using Azure CLI
{
"isFallbackPublicClient": true,
"publicClient": {
"redirectUris": [
"https://login.microsoftonline.com/common/oauth2/nativeclient"
]
},
"web": {
"implicitGrantSettings": {
"enableIdTokenIssuance": false
import { sp } from "@pnp/sp/presets/all";
import "@pnp/sp/taxonomy";
import { taxonomy, ITerm, ITermData } from "@pnp/sp-taxonomy"
(async () => {
interface ITermDataNode {
Id: string;
ParentTermId?: string;
Name: string;
Path: string;
@phillipharding
phillipharding / Create new ClientsidePage using PnPJS.ts
Last active September 16, 2020 10:39
Create new ClientsidePage using PnPJS
import { sp, ClientsidePageFromFile, PromotedState, IListItemFormUpdateValue, IClientsidePage, IFileInfo } from "@pnp/sp/presets/all";
console.clear();
function SafeFilename(fileName: string, convertToLower?: boolean): string {
const name = (fileName || "")
.replace(/[^ a-zA-Z0-9-_]*/gi, "")
.replace(/ /gi, "-")
.replace(/-*$/gi, "")
.replace(/[-]{2,}/gi, "-");
return convertToLower ? name.toLowerCase() : name;
@phillipharding
phillipharding / Search for Modern News Page Content using PnPJS.ts
Created September 11, 2020 16:47
Search for Modern News Page Content using PnPJS
import { sp, SearchResults, SearchQueryInit, ISearchResult } from "@pnp/sp/presets/all";
console.clear();
function parseUserFormattedString(ownerString) {
const owners = ownerString.split(";")
.map( (owner) => {
const parts = owner.trim().split("|");
const oidstr = parts.splice(2,3).join("").trim();
const oids = oidstr.split(" ");
return {