Skip to content

Instantly share code, notes, and snippets.

Avatar

James Callaghan jcallaghan

View GitHub Profile
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)
{
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
View Hub Site.json
{
"headerEmphasis":null,
"themeKey":null,
"name":"SharePoint Hub Site",
"url":"https://[tenant].sharepoint.com/sites/[site]",
"logoUrl":null,
"usesMetadataNavigation":false,
"megaMenuEnabled":true,
"navigation":[{
"Id":2004,
View Set-SPOFooter.ps1
function Get-BearerToken() {
<#
.SYNOPSIS
Gets an access token.
.DESCRIPTION
This is a custom function that returns an access token.
Assumes Connect-PnpOnline has already been established.
#>
$token = Get-PnPAppAuthAccessToken
@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(