Skip to content

Instantly share code, notes, and snippets.

View aflyen's full-sized avatar

Are Flyen aflyen

View GitHub Profile
@aflyen
aflyen / SetDefaultAudienceOnSitePages.ps1
Created March 1, 2022 12:46
Set a default audience on all new articles (incl. news links) in the Site Pages library for modern communication sites in SharePoint Online.
# Connect to the modern communication site
Connect-PnPOnline -Url https://consotos.sharepoint.com
# Get the Site Pages library
$List = Get-PnPList -Identity "SitePages" -Includes Fields
# Go the the Site Pages library, enable audience targeting, add a news template and set a default value.
# Get news tempalte with default settings
$TemplateItem = Get-PnPListItem -List $List | Where-Object { $_.FieldValues.FileLeafRef -eq "ContosoNews.aspx" }
@aflyen
aflyen / RedirectClassicPagesToModern.ps1
Last active March 1, 2022 12:48
Redirect classic publishing pages to modern communication sites on upgrading intranetsin SharePoint Online
# Connect to the site
Connect-PnPOnline -Url https://contoso.sharepoint.com
# Create a new classic Wiki Pages library
New-PnPList -Title "Pages-Redirect" -Url "Pages" -Template:WebPageLibrary
# Go to the "Pages" library and add a new page "Default" and enter information about where the new site can be found.
@aflyen
aflyen / EnableM365SensitivityLabelsOnGroups.ps1
Created January 31, 2022 14:54
Enable the use of sensitivity labels on Microsoft 365 groups
# Requires: Install-Module -Name ExchangeOnlineManagement -RequiredVersion 2.0.5
Import-Module ExchangeOnlineManagement
Connect-IPPSSession
Execute-AzureAdLabelSync
@aflyen
aflyen / AddMultiLanguageSupportToSpoSite.cs
Last active November 25, 2021 22:34
Enables multi language support for existing sites in SharePoint Online using CSOM
var siteUri = new Uri("https://contoso.sharepoint.com/sites/teamsite1");
string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
var accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, siteUri.Authority, realm).AccessToken;
using (var clientContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), accessToken))
{
var web = clientContext.Web;
clientContext.Load(web, w => w.SupportedUILanguageIds, w => w.Language, w => w.RegionalSettings.InstalledLanguages);
clientContext.ExecuteQuery();
@aflyen
aflyen / Set-CorpMultiLanguageSupport.ps1
Last active November 25, 2021 22:34
Enables multi language support for an existing site in SharePoint Online using the PnP.PowerShell module
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/teamsite1"
$Web = Get-PnPWeb -Includes SupportedUILanguageIds,Language
$AvailableLanguages = Get-PnPAvailableLanguage
# Enable multi language support
$Web.IsMultilingual = $true
# Add UI support for additional languages
foreach ($AvailableLanguage in $AvailableLanguages)
{
# Log event to file
function Add-CorpLog
{
param(
[Parameter(Mandatory=$true)]
[string]$Message
)
if ($CorpWriteLogToConsole -eq $True)
{
# Connects to Azure Active Directory to authenticate and retrieve a valid access token using a Client ID and secret
function Get-CorpMicrosoftGraphAccessToken
{
param(
[string] $TenantId,
[string] $ClientId,
[string] $ClientSecret
)
$AccessToken = ""
# Configuration
$SiteUrl = "https://TENANTID.sharepoint.com"
$TermGroupName = "Contoso"
$TermSetName = "Document Types"
$TermName = "Reports"
$TermLcid = 1033
$TermGuid = "2bdb40fd-02e4-4604-914e-9f8012685be0"
# Get correct termset
Connect-PnPOnline -Url $SiteUrl -Credentials $GlobalCredentialsId
# Configuration
$TenantUrl = "https://contoso.sharepoint.com"
$Username = "danj@contoso.com"
$Password = "Password1"
$SiteTitle = "My Communication Site 1"
$SiteUrl = "https://contoso.sharepoint.com/sites/mycomsite1" # Note this URL must be available (check with "/_api/GroupSiteManager/GetValidSiteUrlFromAlias")
$SiteTemplate = "" # "Topic" => leave empty (default), "Showcase" => "6142d2a0-63a5-4ba0-aede-d9fefca2c767" and "Blank" => "f6cc5403-0d63-442e-96c0-285923709ffc"
# Communication site creation request
<# .SYNOPSIS
Title of the script
.DESCRIPTION
Description of the script
.NOTES
Author : Are Flyen
Date : 23.03.2023
.LINK
https://www.areflyen.no
#>