Skip to content

Instantly share code, notes, and snippets.

View star-crossed's full-sized avatar

Paul Choquette star-crossed

  • Everett, WA
View GitHub Profile
@star-crossed
star-crossed / New-LastModifiedZip.ps1
Created May 21, 2018 19:58
A PowerShell script to recursively zip all files that were last modified on or after the supplied start date.
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, HelpMessage = "This is the date used for filtering.")]
[string]$StartDate
)
$ParsedDate = [System.DateTime]$StartDate
$CurrentPath = (Get-Item -Path ".\").FullName
$CurrentFolder = (Get-Item -Path ".\").Name
Get-ChildItem -Path . -Recurse -Attributes !D | Where-Object {
@star-crossed
star-crossed / PeoplePickerString.cs
Created January 26, 2018 15:46
String for the people picker used for the ShareObject method
var peoplePickerValue = "[{\"Key\":\"" + user.Email + "\",\"Description\":\"" + user.Email + "\",\"DisplayText\":\"" + user.Email + "\",\"EntityType\":\"\",\"ProviderDisplayName\":\"\",\"ProviderName\":\"\",\"IsResolved\":true,\"EntityData\":{\"SPUserID\":\"" + user.Email + "\",\"Email\":\"" + user.Email + "\",\"IsBlocked\":\"False\",\"PrincipalType\":\"UNVALIDATED_EMAIL_ADDRESS\",\"AccountName\":\"" + user.Email + "\",\"SIPAddress\":\"" + user.Email + "\"},\"MultipleMatches\":[],\"AutoFillKey\":\"" + user.Email + "\",\"AutoFillDisplayText\":\"" + user.Email + "\",\"AutoFillSubDisplayText\":\"\",\"AutoFillTitleText\":\"" + user.Email + "\n" + user.Email + "\",\"DomainText\":\"$domain\",\"Resolved\":true}]";
@star-crossed
star-crossed / Use-WindowsCredentialManager.ps1
Last active October 2, 2017 20:44
A snippet for keeping a credential in Windows Credential Manager
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false)][Boolean]$setCredentials
)
Set-Strictmode -Version 1
Import-Module CredentialManager
If ($PSCommandPath -eq $null) {
@star-crossed
star-crossed / O365QuickLaunchSortRecursive.ps1
Last active June 19, 2017 20:06
A PowerShell script SharePoint Online that will recursively sort the Quick Launch navigation for a web and its subwebs
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, HelpMessage="This is the URL to the SharePoint Online site.")]
[string]$Url,
[Parameter(Mandatory=$true, HelpMessage="This is the ordering method: 0=Automatic, 1=Manual with Automatic Page Sorting, 2=Manual.")]
[ValidateSet(0, 1, 2)]
[int]$OrderingMethod,
[Parameter(Mandatory=$true, HelpMessage="This is the automatic sorting method: 0=Title, 1=Created Date, 2=Last Modified Date.")]
@star-crossed
star-crossed / SPPromoteListColumnToSiteColumn.ps1
Created April 18, 2017 20:18
PowerShell script for SharePoint using CSOM to take a list column and "promote" it to a site column.
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, HelpMessage="This is the URL to the SharePoint Online site.")]
[string]$Url,
[Parameter(Mandatory=$false, HelpMessage="This is the path to the DLLs for CSOM.")]
[string]$CSOMPath
)
Set-Strictmode -Version 1
@star-crossed
star-crossed / O365WebInheritanceReset.ps1
Created April 7, 2017 15:52
PowerShell script for SharePoint Online to reset all subwebs, lists, and list items in a web.
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, HelpMessage="This is the URL to the SharePoint Online site where you want to reset inheritance.")]
[string]$Url,
[Parameter(Mandatory=$false, HelpMessage="If true, all subwebs will be reset as well.")]
[Boolean]$Subwebs,
[Parameter(Mandatory=$false, HelpMessage="This is the path to the DLLs for CSOM.")]
[string]$CSOMPath
@star-crossed
star-crossed / Batching.ps1
Created March 31, 2017 18:53
Example of adding row number and grouping by 200 to allow batches for CSOM's ExecuteQuery
$csv | ForEach-Object {
Add-Member -InputObject $_ -MemberType NoteProperty -Name 'Row' -Value ([int]($csv.IndexOf($_) / 200))
} | Group-Object -Property 'Row' | ForEach-Object {
$_.Group | ForEach-Object {
# Compose your batch
}
$context.ExecuteQuery()
}
@star-crossed
star-crossed / SP-GetRoleAssignmentsRecursive.ps1
Last active August 12, 2017 19:42
Recursively gets RoleAssignments for a SharePoint site and subsites
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, HelpMessage="This is the path to the CSV file.")]
[string]$CSVFile,
[Parameter(Mandatory=$true, HelpMessage="This is the URL to the SharePoint Online site.")]
[string]$Url,
[Parameter(Mandatory=$false, HelpMessage="This is the path to the DLLs for CSOM.")]
[string]$CSOMPath
@star-crossed
star-crossed / SP-GetFilesRecursive.ps1
Last active August 12, 2017 19:48
Recursively get files in SharePoint
$spWeb = get-SPWeb "localhost"
function getFiles ([Microsoft.SharePoint.SPFolder]$parentFolder) {
$files = $parentFolder.Files
foreach($file in $files) {
Write-Host $file.Name $file.TimeLastModified
$b = $file.OpenBinary()
$fs = New-Object System.IO.FileStream(("\\server\exportfiles\"+$file.name), [System.IO.FileMode]::Create)
$bw = New-Object System.IO.BinaryWrite($fs)
@star-crossed
star-crossed / DisableDurableLinks.js
Last active August 19, 2016 17:50
This JavaScript can be added to a page in SharePoint Online to disable the durable link display in the document preview callout.