Skip to content

Instantly share code, notes, and snippets.

View damsleth's full-sized avatar
🏡
Locally sourced, home-grown, artisanal automatrons

Carl Joakim Damsleth damsleth

🏡
Locally sourced, home-grown, artisanal automatrons
View GitHub Profile
@damsleth
damsleth / Patch-SpPagesAssembly.ps1
Last active October 11, 2023 11:56
Patch for SharePoint Server Subscription Edition 23H2 CU, sp-pages-assembly
<#
.SYNOPSIS
This script patches a recursion bug in the file 'sp-pages-assembly.js', in the 23H2 release of SharePoint Subscription Edition.
.COMPONENT
SharePoint Server Subscription Edition 23H2
.NOTES
This script is provided as-is, without any warranty or support what so ever.
It is not supported by Microsoft, and is provided as a courtesy to the community.
Use at your own risk.
.DESCRIPTION
@damsleth
damsleth / SPUpload.ps1
Created October 20, 2022 13:51
SPFx helper script for packaging and uploading the resulting `.sppkg` to your SharePoint tenant using PnP.PowerShell
function SPUpload() {
Param(
[Parameter(Mandatory = $true)]
[string] $Tenant
)
gulp clean;
gulp bundle;
gulp package-solution --ship;
# Comment this in if you have the insertSourceMaps-task in your gulpfile/repo
# See https://github.com/damsleth/spfx-source-maps
@damsleth
damsleth / OWAEventDuplicator
Last active December 18, 2023 13:33
Hack to duplicate calendar events by holding down the meta (cmd) key and right clicking them in Outlook Web Access
// ==UserScript==
// @name OWAEventDuplicator
// @namespace http://tampermonkey.net/
// @version 0.3.2
// @description Duplicate events by holding down the meta key and right clicking them
// @author @damsleth
// @match https://outlook.office.com/calendar/view/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=office.com
// @grant none
// ==/UserScript==
@damsleth
damsleth / PnP.PowerShell-Compatibility
Created October 27, 2020 22:03
Snippet for making old SharePointPnPPowerShellOnline scripts compatible with the newer, cross platform PnP.PowerShell cmdlets
if(gmo -Name "PnP.PowerShell"){
sal -Name Apply-PnPProvisioningTemplate -Value Invoke-PnPSiteTemplate
sal -Name Apply-PnPPTenantTemplate -Value Invoke-PnPTenantTemplate
sal -Name Get-PnPProvisioningTemplate -Value Get-PnPSiteTemplate
}
@damsleth
damsleth / UpdateAuthorEditor.ps1
Created March 28, 2018 09:33
update author and editor on all splistitems in a library
# get Site. trailing slash mandatory for .openweb
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://SHAREPOINT.com/sites/SITENAME/");
$SPWeb = $SPSite.OpenWeb();
# get documents
$SPList = $SPWeb.Lists["Dokumenter"];
# get all items
$SPListItemCollection = $SPList.Items;
# parameters on SPFieldUserValue are $SPWeb, userId, "#Brukers fulle navn".
# eg $SPWeb,12, "#iAmDevloper2"
# User ID is in User Information List, provided the user has been ensured on the site at some point
@damsleth
damsleth / PdfViewer.js
Created March 28, 2018 08:59
SharePoint PDF preview for document library edit- and viewforms.
const PdfPreview = () => {
let _wopiDOM;
async function GetWopiDOM(docUrl = CurrentItemUrl()) {
if (_wopiDOM) { return _wopiDOM } else {
return fetch(`${_spPageContextInfo.siteAbsoluteUrl}/_layouts/15/WopiFrame.aspx?sourcedoc=${encodeURIComponent(docUrl)}`, { credentials: "include" })
.then(res => res.text().then(wopi => new DOMParser().parseFromString(wopi, "text/html")).then(dom => {
_wopiDOM = dom
return _wopiDOM
}))
}
@damsleth
damsleth / template.xml
Created January 19, 2018 08:54
semi-generic template.xml with xi:included artifacts
<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2016/05/ProvisioningSchema">
<pnp:Preferences>
<pnp:Parameters>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../_Shared/Parameters/GenericContentTypesGroup.xml" />
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../_Shared/Parameters/GenericFieldsGroup.xml" />
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../_Shared/Parameters/GenericFieldsPrefix.xml" />
<pnp:Parameter Key="TemplateDisplayName">TEMPLATENAME</pnp:Parameter>
<!-- wipes some ootb stuff from STS#0 -->
<pnp:Parameter Key="PerformCleanup">True</pnp:Parameter>
@damsleth
damsleth / New-DevSite.ps1
Last active March 28, 2018 09:25
Provisioning a new dev site with PnP
Param(
[Parameter(Mandatory=$false)]
[string]$RootSite = "https://ROOTSITE",
[Parameter(Mandatory=$false)]
[string]$AdminSite = "https://ADMINSITE",
[Parameter(Mandatory=$false)]
[string]$Owner = "i:0#.w|DOMAIN\OWNER",
[Parameter(Mandatory=$true)]
[string]$Name,
[Parameter(Mandatory=$false)]
@damsleth
damsleth / brand-personalsites.ps1
Created January 18, 2018 14:31
Branding MySites using PnP Provisioning templates
Param(
[Parameter(Mandatory=$false)]
[string]$SiteUrl = "https://MYSITEHOSTWEBAPP",
[Parameter(Mandatory=$false)]
[string]$TemplateDir = "./template.xml",
[Parameter(Mandatory=$false)]
[string]$BlogTemplateDir = "./blogtemplate.xml"
)
#
# Brand MySites using PnP Provisioning templates
@damsleth
damsleth / SP-REST-Fetch
Created April 21, 2017 13:11
SharePoint Get REST data with Fetch (with logging function)
const getRestData = endpoint =>
fetch(`${_spPageContextInfo.webAbsoluteUrl}/_api/web/${endpoint}`,
{ credentials: "include", headers: { "accept": "application/json;odata=verbose" } })
.then(res => res.json().then(data => {
return data.d.hasOwnProperty("results") ? data.d.results : data.d }))
.catch(err => console.log(err));
const getListItems = listTitle => { return getRestData(`lists/getbytitle('${listTitle}')/items`) };
const logProps = (endpoint, prop) =>