Skip to content

Instantly share code, notes, and snippets.

View phillipharding's full-sized avatar

Phil Harding phillipharding

View GitHub Profile
@phillipharding
phillipharding / Add-ValidateUpdateListItems.js
Last active July 7, 2023 13:49
SharePoint REST API Add/ValidateUpdateListItems
See:
- https://robertschouten.com/2018/04/30/update-file-metadata-with-rest-api-using-validateupdatelistitem-method/
- http://blog.arvosys.com/2018/07/06/list-items-system-update-options-in-sharepoint-online/index.html
FieldValues =
[
// Text field (single line and note)
{ FieldName: "TextField", FieldValue: "123" },
// Number field
@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
@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 {
@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;
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;
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 July 14, 2020 16:24
Gets Items from a Large Document Library/List (over 5000 items) using a Paged 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">

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

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

REGEX

[~#%&*{}+\\/:<>?|'".]+
const hasInvalidCharacters = teamName.match(/[~#%&*{}+\\/:<>?|'".]+/gi);