Skip to content

Instantly share code, notes, and snippets.

View pkskelly's full-sized avatar

Pete Skelly pkskelly

View GitHub Profile
@pkskelly
pkskelly / Clear-SPListItems.ps1
Last active May 19, 2017 14:17
Clear-SPListItems.ps1 simulates SPWeb.ProcessBatchData() using CSOM to batch ListItemCollection item deletes. Feedback welcome! To see what is going on under the covers, run Fiddler and watch the traffic for the requests.
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Script: Clear-SPListItems.ps1
#
# Author: Pete Skelly
# Twitter: ThreeWillLabs
# http://www.threewill.com
#
# Description: Purge list in Sharepoint Online - Office 365 using CSOM by
# batching CSOM calls to simulate SPWeb.ProcessBatchData().
#
@pkskelly
pkskelly / Add-SPListItemsFromCSV.ps1
Last active October 12, 2015 15:07
Add list items to SharePoint Online - Office 365 List using CSOM from CSV file.
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Script: Add-SPListItemsFromCSV.ps1
#
# Author: Pete Skelly
# Twitter: ThreeWillLabs
# http://www.threewill.com
#
# Description: Add list items to SharePoint Online - Office 365 List using CSOM from CSV file.
#
# WARNING: Script provided AS IS with no warranty. Your mileage will vary. Use
@pkskelly
pkskelly / Delete-SPDocsInBatch.ps1
Last active August 29, 2015 14:01
Snippet from an old script which deletes documents from a SharePoint Document library using SPWeb.ProcessBatchData(). Script used a CSV file of $activities which defined what should be deleted.
if ($clean)
{
$deletedSharedDocs = $false;
Write-Host "`n`nCleaning all lists of all content...Please wait"
foreach($activity in $activities)
{
$web = get-web $activity.RootUrl
$list = $web.Lists[$activity.ListName];
\ if ($list.BaseType -eq "DocumentLibrary" -and ($list.ItemCount -gt 0))
@pkskelly
pkskelly / Install-DevTools.ps1
Last active August 29, 2015 14:06
Chocolatey Developer Environment Build Script
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
##Developer Tools
#cinst sysinternals
#cinst 7zip
cinst diffmerge
#cinst winmerge
#cinst fiddler
#cinst paint.net
#cinst githubforwindows
@pkskelly
pkskelly / TW-CreateBlankClientExtranetSite.ps1
Created December 3, 2014 20:06
Add a blank site collection to an Office 365 tenant in SharePoint Online
# =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Script: TW-CreateBlankClientExtranetSite.ps1
#
# Author: Pete Skelly
# Twitter: ThreeWillLabs
# http://www.threewill.com
#
# Description: Add a blank site collection to an Office 365 tenant in SharePoint Online
#
# WARNING: Script provided AS IS with no warranty. Your mileage will vary. Use
@pkskelly
pkskelly / RemoveSiteOrphans.ps1
Created January 29, 2015 16:06
Removes Orphaned Sites from a Content Database
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction "SilentlyContinue"
cls
Set-Alias -Name stsadm -Value $env:CommonProgramFiles”\Microsoft Shared\Web Server Extensions\15\BIN\STSADM.EXE”
function RemoveOrphanedSites([string]$WebAppUrl, [switch]$ReportOnly)
{
$configDB = Get-SPDatabase | where {$_.typename -eq "Configuration Database"}
$contentDBs = Get-SPWebApplication -IncludeCentralAdministration | Get-SPContentDatabase
foreach($contentDB in $contentDBs)
@pkskelly
pkskelly / O365Logout.html
Last active January 15, 2019 11:17
Link to log out of Office 365 or SharePoint 2013. Simply copy this file locally, open in a browser and drag the link to the bookmarks bar. Clicking the book mark will force a log out.
<html>
<head>
<title>Logout</title>
</head>
<!-- See http://blog.credera.com/technology-insights/microsoft-solutions/how-to-sign-in-as-a-different-user-in-sharepoint-2013/ for original script-->
<body>
<a href="javascript:
(function()
{
if (typeof SP !== 'undefined')
@pkskelly
pkskelly / Add-GoogleAnalyticsToO365.ps1
Last active August 29, 2015 14:15
Adds a Google Analytics script to all /teams/* site collections in an Office 365 Tenant.
<#
.SYNOPSIS
Adds a Google Analytics script to all /teams/* site collections in an Office
365 Tenant.
.DESCRIPTION
When using Office 365 "/teams/*" managed path site collections as an extranet, some
clients would like to track their traffic using Google Analytics. This is a
simple script that adds the Google Analytics script to a UserCustomAction
using the http://github.com/officedev.pnp PowerShell cmdlet's to manage SharePoint
. .\TopOfScript_PSCSOM.ps1
function listEventReceivers([Microsoft.SharePoint.Client.ClientContext]$context, [string]$listName)
{
Write-Host "Attempting to iterate event receivers on list '$listName'"
$list = $context.Web.Lists.GetByTitle($listName);
$context.Load($list)
$eventReceivers = $list.EventReceivers
$context.Load($eventReceivers)
@pkskelly
pkskelly / ToCSV.cs
Created April 14, 2015 19:40
Simple (Very) C# Extension Method for conversion to a CSV list
public static string ToCsv<T>(string separator, IEnumerable<T> objectlist)
{
Type t = typeof(T);
FieldInfo[] fields = t.GetFields();
string header = String.Join(separator, fields.Select(f => f.Name).ToArray());
StringBuilder csvdata = new StringBuilder();
csvdata.AppendLine(header);