Skip to content

Instantly share code, notes, and snippets.

View aflyen's full-sized avatar

Are Flyen aflyen

View GitHub Profile
function Get-CustomLoadParameter {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[Microsoft.SharePoint.Client.ClientObject]$Object,
[Parameter(Mandatory=$true)]
[string]$PropertyName
)
# Reference: http://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell
function Enable-CustomItemScheduling {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[Microsoft.SharePoint.Client.Web]$Web,
[Parameter(Mandatory=$true)]
[String]$PagesLibraryName
)
$List = $Web.Lists.GetByTitle($PagesLibraryName)
$Context = Get-SPOContext
$Web = $Context.Site.RootWeb
$Context.Load($Web)
Execute-SPOQuery
Enable-CustomItemScheduling -Web $Web -PagesLibraryName "Pages"
@aflyen
aflyen / EnableExportOnWebParts.ps1
Last active October 28, 2015 11:46
Enable export on web parts in SharePoint (on-premises)
# Configuration
$WebUrl = "http://intranet.contoso.com"
$PageUrl = "/Pages/default.aspx"
$WebPartName = "Documents"
# Enables export mode
$Web = Get-SPWeb $WebUrl
$File = $Web.GetFile($Web.ServerRelativeUrl + $PageUrl)
$File.CheckOut()
$Wpm = $File.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
# Configuration
$WebUrl = "http://teams.contoso.com/sites/team1"
$SiteAdminGroup = "CONTOSO\ContosoSiteAdmins"
# Set the AD group as site collection administrator
$Web = Get-SPWeb $WebUrl
$SiteAdminUser = $Web.EnsureUser($SiteAdminGroup)
$SiteAdminUser.IsSiteAdmin = $true
$SiteAdminUser.Update()
# Connect to SharePoint Online site collection and get context
Connect-SPOnline -Url "https://TENANTID.sharepoint.com/sites/news
$Context = Get-SPOContext
$Web = $Context.Site.RootWeb
$Context.Load($Web)
Execute-SPOQuery
# Enable likes ratings
Enable-CustomLikesRatingsOnLibrary -Web $Web -ListRelativeUrl "Pages"
# Settings
$Username = "aflyen@northcorp.no"
# Connect to Azure AD
Connect-AzureAD
# Get user
$User = Get-AzureADUser -ObjectId $Username
Write-Host "Before: $($User.PreferredLanguage)"
function addMigrationInfo(sender, args) {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {
var statusId = SP.UI.Status.addStatus("This site has moved. Please update you bookmarks and visit the new location: <a href='" + url + "'>" + url + "</a>");
SP.UI.Status.setStatusPriColor(statusId, 'yellow');
});
}
// Initialize the statusbar as late as possible, see: https://blog.josequinto.com/2015/06/16/custom-javascript-function-loaded-after-the-ui-has-loaded-in-sharepoint-2013/
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(addMigrationInfo);
<# .SYNOPSIS
Restrict Office 365 Groups creation
.DESCRIPTION
Restrict creation to only users in a specific Azure AD security group. Requires the Azure AD Preview PowerShell module to be installed (this or newer version): https://www.powershellgallery.com/packages/AzureADPreview/2.0.0.98
.NOTES
Author : Are Flyen
.LINK
http://blog.areflyen.no
#>
# 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