Skip to content

Instantly share code, notes, and snippets.

Avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / SharePoint PnPJS Parallel ListItem Update with Retry
Last active Feb 14, 2021
Updates a SharePoint listitem in parallel using PnPJS with retry capability if error 409 (item has been updated by another user or process) occurs
View SharePoint PnPJS Parallel ListItem Update with Retry
/*
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 Oct 17, 2020 — forked from garrytrinder/m365-identity.sh
Create custom Azure AD identity for use with CLI for Microsoft 365 using Azure CLI
View body.json
{
"isFallbackPublicClient": true,
"publicClient": {
"redirectUris": [
"https://login.microsoftonline.com/common/oauth2/nativeclient"
]
},
"web": {
"implicitGrantSettings": {
"enableIdTokenIssuance": false
View Get Taxonomy Terms Hierarchy using PnPJS
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 Sep 16, 2020
Create new ClientsidePage using PnPJS
View Create new ClientsidePage using PnPJS.ts
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 Sep 11, 2020
Search for Modern News Page Content using PnPJS
View Search for Modern News Page Content using PnPJS.ts
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 {
View Create and Locate an Item in a JSON Tree
json = [
{
key: 1,
id: 1,
label: "Parent #1",
isexpanded: false,
children: [
{
key: 11,
id: 11,
@phillipharding
phillipharding / Get Paged Items from a Large List using RenderListDataAsStream
Last active Jul 14, 2020
Gets Items from a Large Document Library/List (over 5000 items) using a Paged RenderListDataAsStream
View Get Paged Items from a Large List using RenderListDataAsStream
import { sp } from "@pnp/sp/presets/all";
(async () => {
console.clear();
const doPagedQuery = (folder: string, rowLimit: number, scope: "Files"|"Folders", pageToken?: string) => {
const list = sp.web.getList('/sites/EDMS_InformationGovernance/Shared%20Documents');
return list.renderListDataAsStream({
ViewXml: `
<View Scope="RecursiveAll">
View NVM Commands.md

NVM version

nvm --version

List versions of Node installed

nvm ls --no-alias

List current version of Node

nvm current

Use the specified version of Node

View Matching Invalid Characters in Team & Channel Names.md

~ # % & * { } + \ / : < > ? | " .

REGEX

[~#%&*{}+\\/:<>?|'".]+
const hasInvalidCharacters = teamName.match(/[~#%&*{}+\\/:<>?|'".]+/gi);
@phillipharding
phillipharding / Remove .DS_Store files.sh
Created Apr 28, 2020
Recursively removes .DS_Store files
View Remove .DS_Store files.sh
## Recursively Remove .DS_Store
# Show
find . -name '.DS_Store' -type f
# Remove
find . -name '.DS_Store' -type f -delete