Skip to content

Instantly share code, notes, and snippets.

View jcallaghan's full-sized avatar

James Callaghan jcallaghan

View GitHub Profile
@jcallaghan
jcallaghan / Microsoft-SharePoint-Get-SPWebPartsOnPage.ps1
Last active October 24, 2019 12:41
List all web parts that have been used on site pages in a given SharePoint Online site. Legacy approach.
# 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 October 24, 2019 12:41
Connect to SharePoint Online using CSOM DLLs (Legacy method)
$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(
$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 December 12, 2017 10:27
Override created by or modified by property in SharePoint
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 October 25, 2020 06:04
Apply configuration for Office3 365 Group Classification
<#
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)
#>
# 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
# 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() {
# 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() {
# 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
<#
# 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