Skip to content

Instantly share code, notes, and snippets.

@OlafD
OlafD / CreateFAQList.ps1
Created March 27, 2019 11:16
Script to create the FAQ sample structure.
param (
[Parameter(Mandatory=$true)]
$Url,
$Cred,
[switch]$UseWebLogin
)
if ($UseWebLogin.ToBool() -eq $false)
{
if ($Cred -eq $null)
@OlafD
OlafD / LoadFAQ.html
Created March 27, 2019 11:18
Html and JavaScript to embed on a SharePoint wiki page with a Content Editor Webpart. This file is part of the FAQ sample solution.
<style>
.accordion {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
text-align: left;
@OlafD
OlafD / DocumentTextFromOCR.xml
Created April 18, 2019 08:39
Very simple proof of concept for indexing pdf files iin SharePoint online that are results of scanned content and contain mainly images. This sample uses IronOcr to get the text content of the file.
<Field
ID="{1012e6c5-2eb5-44cf-9f73-1ed8a584d38b}"
Name="DocumentTextFromOCR"
DisplayName="Document Text from OCR"
Description=""
StaticName="DocumentTextFromOCR"
Group="Demo"
Type="Note"
NumLines="10"
UnlimitedLengthInDocumentLibrary="TRUE"
@OlafD
OlafD / HideFieldInEditForm.ps1
Created April 25, 2019 17:29
For a field in a list set the property, to make it hidden in the edit form.
$field = Get-PnPField -List "My List" -Identity "Target Date"
$field.SetShowInEditForm($false)
$field.Update()
Invoke-PnPQuery
@OlafD
OlafD / AddFieldToFolderCT.ps1
Created May 8, 2019 06:49
Add a field to the (sealed) content type "Folder" in a library.
# 1) unseal the content type for folders in the library
$ct = Get-PnPContentType -Identity "Folder" -List "Documents"
$ct.Sealed = $false
$ct.Update($false) # using $true in this case will throw an execption
Invoke-PnPQuery
# 2) add the description field (must already exist) to the Folder content type
@OlafD
OlafD / MakeTitleVisibleForFolders.ps1
Created May 9, 2019 06:39
Make the title field visible for editing in the Folder content type in a library in SharePoint.
# get the content type from the library
$ct = Get-PnPContentType -Identity "Folder" -List "Documents"
# get the fieldlinks collection from the content type
$fieldLinks = $ct.FieldLinks
(Get-PnPContext).Load($fieldLinks)
Invoke-PnPQuery
# get the title field from the site columns
$titleField = Get-PnPField -Identity "Title"
@OlafD
OlafD / ModifySurveyOverview.html
Created May 15, 2019 12:49
Hide Number of Responses in a survey overview.
<script type="text/javascript">
$( document ).ready(function() {
$("#overview04").parent().hide();
});
</script>
@OlafD
OlafD / ChangeFieldType.ps1
Created May 28, 2019 12:27
Change the FieldTypeKind of a field using PowerShell PnP.
$field = Get-PnPField -List "Documents" -Identity "Users" -Includes FieldTypeKind
$field.FieldTypeKind = [Microsoft.SharePoint.Client.FieldType]::User
$field.Update()
Invoke-PnPQuery
@OlafD
OlafD / SharePointCSOMQueryLargeLists.cs
Created July 31, 2019 06:09
Simple sample for looping a list with a caml query for a list with more than 5000 items.
List list = _ctx.Web.Lists.GetByTitle(Constants.Listnames.DocumentHistoryList);
_ctx.Load(list);
_ctx.ExecuteQueryRetry();
ListItemCollectionPosition collectionPosition = null;
CamlQuery query = new CamlQuery();
query.AllowIncrementalResults = true;
@OlafD
OlafD / GetGroupsAndMemberships.ps1
Created August 21, 2019 11:33
When connected to a SharePoint site with PowerShell PnP, list all groups and the group members. The script will not show any kind of permissions.
Write-Host
Write-Host "Groups Overview"
Write-Host "==============="
Write-Host
$groups = Get-PnPGroup
foreach ($group in $groups)
{