Skip to content

Instantly share code, notes, and snippets.

Avatar

James Callaghan jcallaghan

View GitHub Profile
@jcallaghan
jcallaghan / Microsoft-SharePoint-Get-SPWebPartsOnPage.ps1
Last active Oct 24, 2019
List all web parts that have been used on site pages in a given SharePoint Online site. Legacy approach.
View Microsoft-SharePoint-Get-SPWebPartsOnPage.ps1
# Connect to SPO (see seperate connect function - https://gist.github.com/jcallaghan/d61d4bd8d23fbadf9687434a0a49dd2d)
$context = Connect-SPO -url "https://tenant.sharepoint.com//"
# Get web
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
Write-Host "Processing web with URL: '$($web.Url)'"
# Get pages library
@jcallaghan
jcallaghan / Microsoft-SPO-Connect.ps1
Last active Oct 24, 2019
Connect to SharePoint Online using CSOM DLLs (Legacy method)
View Microsoft-SPO-Connect.ps1
$username = "username@tenant.onmicrosoft.com"
$securePassword = Read-Host -Prompt "Enter password" -AsSecureString
$SecurePassword = $securePassword | ConvertTo-SecureString -AsPlainText -Force
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
function Connect-SPO{
Param(
View Microsoft-SPO-CSOM-Set-WebPartChromeType.ps1
$wpManager = $file.GetLimitedWebPartManager([Microsoft.SharePoint.Client.WebParts.PersonalizationScope]::Shared)
$webparts = $wpManager.Webparts
$clientContext.Load($webparts)
$clientContext.ExecuteQuery()
if($webparts.Count -gt 0){
Write-Host "Looping through all webparts"
foreach($webpart in $webparts){
$clientContext.Load($webpart.WebPart.Properties)
$clientContext.ExecuteQuery()
@jcallaghan
jcallaghan / SPCreatedModifiedByOverride.cs
Created Dec 12, 2017
Override created by or modified by property in SharePoint
View SPCreatedModifiedByOverride.cs
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["Shared Documents"];
SPListItemCollection items = list.Items;
SPListItemCollection oListCollection = list.Items;
foreach (SPListItem oListItem in oListCollection)
{
@jcallaghan
jcallaghan / Create-AADGroupClassification.ps1
Last active Oct 25, 2020
Apply configuration for Office3 365 Group Classification
View Create-AADGroupClassification.ps1
<#
Azure Active Directory cmdlets for configuring group settings
Reference - https://docs.microsoft.com/en-gb/azure/active-directory/users-groups-roles/groups-settings-cmdlets
Note:
Update group classifications (lines 39 and 40)
Set GroupCreationAllowedGroupId to your group if change is required (lines 30 and 31)
#>
View Create-LegacyDataSites.ps1
# Variables
$tenant = "tenant"
$adminUrl = "https://" + $tenant + "-admin.sharepoint.com"
$baseUrl = "https://" + $tenant + ".sharepoint.com"
$registerUrl = $baseUrl + "/sites/sitealias"
$registerListName = "Site Register"
$path = "C:\path\LegacyDataSites.csv"
$csv = Import-csv -path $path
View Create-YammerGroups.ps1
# Yammer app developer token
$token = ""
# Base Yammer API url
$yammerBaseUrl = "https://www.yammer.com/api/v1"
# Reference - Yammer Group
#$createGroupUri = "https://www.yammer.com/api/v1/groups.json?name=Example&private=True"
function Get-BaererToken() {
View Get-YammerGroups.ps1
# Yammer app developer token
$token = ""
# Base Yammer API url
$yammerBaseUrl = "https://www.yammer.com/api/v1"
# Reference - Yammer Group
#$createGroupUri = "https://www.yammer.com/api/v1/groups.json?name=Example&private=True"
function Get-BaererToken() {
View Get-SPOHubSiteStructure.ps1
# Get Hub sites
Connect-SPOService -Url "https://[tenant]-admin.sharepoint.com"
$spoHubSites = Get-SPOHubSite
foreach($hub in $spoHubSites){
$hubSiteId = $hub.SiteId
Write-Host "$($hub.Title) ($($hub.SiteUrl))" -ForegroundColor Yellow
$spoSites = Get-SPOSite -Limit All
foreach ($site in $spoSites) {
$siteDetailed = Get-SPOSite -Detailed $site.Url
View Add-TeamsUsersBulk.ps1
<#
# Reference
Teams PowerShell - https://docs.microsoft.com/en-us/powershell/module/teams/?view=teams-ps
Add-TeamsUser - https://docs.microsoft.com/en-us/powershell/module/teams/add-teamuser?view=teams-ps
# PowerShell Module
Find-Module MicrosoftTeams
Install-Module MicrosoftTeams
Get-Command –Module MicrosoftTeams