Skip to content

Instantly share code, notes, and snippets.

View jcallaghan's full-sized avatar

James Callaghan jcallaghan

View GitHub Profile
$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)
{
# 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
{
"headerEmphasis":null,
"themeKey":null,
"name":"SharePoint Hub Site",
"url":"https://[tenant].sharepoint.com/sites/[site]",
"logoUrl":null,
"usesMetadataNavigation":false,
"megaMenuEnabled":true,
"navigation":[{
"Id":2004,
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 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(