Skip to content

Instantly share code, notes, and snippets.

[CmdletBinding(DefaultParameterSetName = "Interactive")]
param (
[Parameter(Mandatory, ParameterSetName = "UserPassword")]
[Parameter(Mandatory, ParameterSetName = "Interactive")]
[Parameter(Mandatory, ParameterSetName = "AppIDCertificate")]
[string] $Url,
[Parameter(Mandatory, ParameterSetName = "UserPassword")]
[pscredential] $Credentials,
@OlafD
OlafD / DeployRemoteTimerJobKudo.ps1
Created March 16, 2022 09:58
Deploy the release build of a web job from an ASP.Net project to an Azure App Service. The ExeFile parameter must not have a blank. To run the script Azure CLI is needed on the machine to get the publish credentials from the app service.
param (
[Parameter(Mandatory=$true)]
[string]$BuildOutput,
[Parameter(Mandatory=$true)]
[string]$ExeFile,
[Parameter(Mandatory=$true)]
[string]$WebApp,
[Parameter(Mandatory=$true)]
[string]$ResourceGroup,
[Parameter(Mandatory=$true)]
@OlafD
OlafD / FileVersionDownload.ps1
Last active November 21, 2020 15:58
For a document by its item id download all versions incl. the current.
param (
[string]$Url,
[string]$Listname,
[int]$ItemId,
$Credentials,
[string]$DownloadFolder
)
if ($Credentials -eq $null)
{
@OlafD
OlafD / ReplaceMailAddresses.ps1
Created September 16, 2020 12:40
To be used with the output of the Get-PnPProvisioningTemplate cmdlet, this script will replace all mail addresses (user accounts) in the xml file of the output with one static mail address. This is useful, when also content (pages) need to be moved to another tenant.
param (
$InFile,
$OutFile,
$MailDomain,
$ReplaceWith
)
$regexFind = "\b[A-Z0-9._%+-]+@$MailDomain\b"
$inputContent = Get-Content $InFile
@OlafD
OlafD / UniversalTimeForCamlQuery.ps1
Created August 12, 2020 09:06
For using a datetime value in a SharePoint Caml Query, the value needs to be fomatted in the right way. The next two lines will help on this, when it is needed in PowerShell, should also help for C# code.
$date = Get-Date
$zulu = $date.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
@OlafD
OlafD / BulkAddListItems.ps1
Created August 12, 2020 09:00
In case for a SharePoint list a lot of list items are needed for testing (eg. for threshold problems), this script could be used. Be sure to use the correct fieldnames in the for-loop. The items will be commited in batches, to speed-up the process.
param (
[string]$Url,
[string]$List,
[int]$NumberOfItems,
[int]$StartAt = 1,
[int]$CommitAfter = 100,
$Credentials
)
if ($Credentials -eq $null)
@OlafD
OlafD / LoadCSOMLibraries.ps1
Created August 2, 2020 11:32
Load SharePoint Online CSOM libraries from path, where PowerShell PnP extensions are installed. The module folder contains all CSOM libraries for SharePoint Online.
$pnpModulePath = (Get-Module -Name SharePointPnPPowerShellOnline).Path
Add-Type -Path "$pnpModulePath\Microsoft.SharePoint.Client.dll"
Add-Type -Path "$pnpModulePath\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "$pnpModulePath\Microsoft.SharePoint.Client.WorkflowServices.dll"
@OlafD
OlafD / TranscriptSample.ps1
Created July 31, 2020 08:47
Sample for storing a transcript of a PowerShell script execution to a file. The path for the transcript file is a mandatory parameter in the script.
param (
[Parameter(Mandatory=$true)]
[string]$TranscriptPath
)
$scriptName = $MyInvocation.MyCommand.Name.Substring(0, $MyInvocation.MyCommand.Name.IndexOf("."))
$transcriptExtension = Get-Date -Format yyyyMMdd-HHmmss
$transcriptFile = "$TranscriptPath\$scriptName" + "_Transcript_$transcriptExtension.txt"
@OlafD
OlafD / LoopSubwebs.ps1
Created July 31, 2020 08:15
Loop all subwebs of a site collection (root site). Needs the PowerShell PnP extensions for SharePoint Online.
param (
[string]$Url,
$Credentials
)
function LoopWebs
{
param (
$WebCollection
)
@OlafD
OlafD / CreateSiteAssetsLibrary.ps1
Created June 18, 2020 14:58
In a SharePoint Online site with a Communication Site template, the Site Assets library is not created by default. It will automatically added, when a user uploads images or changes the site logo. This script will create the Site Assets library, when it is necessary to have it during other processes after site creation.
Connect-PnPOnline -Url {your_site_url}
$web = Get-PnPWeb
$list = $web.Lists.EnsureSiteAssetsLibrary()
(Get-PnPContext).Load($list)
Invoke-PnPQuery