Skip to content

Instantly share code, notes, and snippets.

@OlafD
OlafD / Add-jQuery.ps1
Created January 10, 2019 08:54
With the PowerShell PnP extensions make jQuery available in the complete site collection in SharePoint Online.
$jsLink = Add-PnPJavaScriptLink -Name "jQuery" -Url "https://code.jquery.com/jquery.min.js" -Sequence 10 -Scope Site
@OlafD
OlafD / ReorderContentTypeFields.ps1
Created January 18, 2019 07:18
Change the field order in a content type by PowerShell. As parameters, we need the name of the content type and the internal name of the field to reorder, and when the Mode parameter is set to Position the zero based number of the new position of the field. The script uses Load-CSOMProperties, a function implemented in the PBSPOPS module. When t…
param (
[Parameter(Mandatory=$true)]
[string]$ContentType,
[Parameter(Mandatory=$true)]
[string]$FieldName,
[ValidateSet("First", "Last", "Position")]
[string]$Mode,
[string]$NewPosition
)
@OlafD
OlafD / GetFieldPositionInContentType.ps1
Created January 18, 2019 07:21
Get the zero-based position of a field, given by its internal name in a content type given by its name. When the field does not exist in the content type, the return value is -1.
param (
[string]$ContentTypeName,
[string]$FieldName
)
$result = -1
$currentPosition = -1
$ct = Get-PnPContentType -Identity $ContentTypeName
@OlafD
OlafD / GetFieldPositionInView.ps1
Created January 18, 2019 07:24
For a list given by its name and for a view in this list given by its name, get the zero-based position of the field given by its internal name. When the field does not exist in the view, the result is -1.
param (
[string]$Listname,
[string]$Viewname,
[string]$Fieldname
)
$result = -1
$currentPosition = -1
$view = Get-PnPView -List $Listname -Identity $Viewname -Includes ViewFields
@OlafD
OlafD / GetSPOVersionHistory.cs
Created January 24, 2019 14:09
A program.cs for a simple console application that shows the version history for a listitem form a SharePoint Online list. This code comes from a simple test application and needs some rework to get a better performance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security;
using Microsoft.SharePoint.Client;
namespace VersioningTester
{
@OlafD
OlafD / ConvertDocX2PdfWithAspose.cs
Created March 6, 2019 10:48
Simple sample code to convert a docx-file to pdf using Aspose.Words. The relevant part is the method SaveAsPdf(). The Nuget package for Aspose.Words needs to be added to the project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Aspose.Words;
using Aspose.Pdf;
@OlafD
OlafD / MergePdf.cs
Created March 6, 2019 11:10
Merge to pdf files from their stream objects into a MemoryStream using Aspose.Pdf.
static MemoryStream MergePdfDocuments(Stream pdf1, Stream pdf2)
{
MemoryStream result = null;
Aspose.Pdf.Document pdf1Document = new Aspose.Pdf.Document(pdf1);
Aspose.Pdf.Document pdf2Document = new Aspose.Pdf.Document(pdf2);
Aspose.Pdf.Document pdfResult = new Aspose.Pdf.Document();
pdfResult.Pages.Add(pdf1Document.Pages);
@OlafD
OlafD / MoveFieldBehind.ps1
Created March 24, 2019 10:57
Move the field to the position behind another field in a content type. This script makes use of two other script files stored as gists.
function MoveFieldBehind
{
param (
[string]$ContentTypeName,
[string]$FieldToMove,
[string]$AnchorField
)
Write-Host "Put field $FieldToMove behind $AnchorField in Content Type $ContentTypeName"
@OlafD
OlafD / CreateDeploymentPackage.ps1
Last active March 26, 2019 11:20
Create a zip-file for the deployment of a WebJob in an Azure Web Application. In the zip-file xml- and pdb-files are excluded.
param (
$Path,
$DestinationPath,
$ZipFile
)
Write-Host "Path: $Path"
Write-Host "DestinationPath: $DestinationPath"
Write-Host "ZipFile: $ZipFile"
@OlafD
OlafD / PowerShellPnP-StartScript.ps1
Created March 27, 2019 07:48
Simple starter für a PowerShell script, when needed to connect to the SharePoint Online site. Can work with credentials or web login.
param (
[Parameter(Mandatory=$true)]
$Url,
$Cred,
[switch]$UseWebLogin
)
if ($UseWebLogin.ToBool() -eq $false)
{
if ($Cred -eq $null)