Skip to content

Instantly share code, notes, and snippets.

View pkskelly's full-sized avatar

Pete Skelly pkskelly

View GitHub Profile
@pkskelly
pkskelly / configureNGStorage.sh
Created December 22, 2017 01:46
Azure CLI script to enable Blob storage containers to serve Angular static files.
#!/bin/bash
AZURE_STORAGE_ACCOUNT=""
AZURE_STORAGE_ACCESS_KEY=""
while getopts "a:k:" opt; do
case $opt in
a)
AZURE_STORAGE_ACCOUNT="${OPTARG}"
;;
@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"
@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 / Send-SendGridMessage.ps1
Created December 2, 2015 20:30
Sending Email from PowerShell using SendGrid (in Azure)
$Username ="azure_*********@azure.com"
$Password = ConvertTo-SecureString "********" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$SMTPServer = "smtp.sendgrid.net"
$EmailFrom = "admin@acme.com"
$EmailTo = "user@acme.com"
$Subject = "SendGrid test"
$Body = "SendGrid testing successful"
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body
@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 / 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);
. .\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 / 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
@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 / 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)