Skip to content

Instantly share code, notes, and snippets.

View pkskelly's full-sized avatar

Pete Skelly pkskelly

View GitHub Profile
@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 / 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 / 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 / SplitPascalCaseVIewNames
Created June 19, 2015 20:34
Extension Method to walk all views in all lists and expand PascalCase view names. E.g. expand "AllItems" to "All Items" in order to keep the %20 chars out of the Url
public static partial class WebExtensions
{
public static void SplitPascalCasedViewNames(this Web web)
{
ListCollection projectLists = web.Lists;
web.Context.Load(projectLists);
web.Context.ExecuteQuery();
foreach (List list in projectLists)
{
ViewCollection listViews = list.Views;
@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 / createproj.sh
Last active March 27, 2017 12:54
Simple .NET Core CLI set of commands to create a solution with referenced projects on a Mac.
#create the solution
dotnet new sln -n CandidateManager
#create the Console project
dotnet new console --name CandidatesConsole --output CandidatesConsole
#create the web project
dotnet new webapi --name CandidatesWeb --output CandidatesWeb
# These are the templates available from ASP.NET JavaScript Services https://github.com/aspnet/JavaScriptServices
@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 / SMATCollector.ps1
Created July 3, 2017 18:11
Simple Script to combine all SMAT CSV files into a single file
$csvFiles = Get-ChildItem $PSScriptRoot -Include *.csv -Recurse
$fileCount = $csvFiles.Count
Write-Host "Processing files: ($fileCount)"
foreach ($csv in $csvFiles) {
Write-Host "Processing $($csv.BaseName)..."
}
$outputfilename = read-host "Please enter the output file name"