Skip to content

Instantly share code, notes, and snippets.

@joerodgers
joerodgers / Get-SPListChoiceFieldValues.ps1
Created October 27, 2017 19:00
Examples how to get choice field values via server API and REST API
# SERVER SIDE API
$web = Get-SPWeb -Identity "https://sharepoint.contoso.com/sites/teamsite"
$list = $web.lists.TryGetList( "Choice Field List" )
$field = $list.Fields.GetField( "Pick One")
$field.Choices
$list.ID
# REST API
@joerodgers
joerodgers / Repair-ConfigCacheParallel.ps1
Last active February 10, 2020 16:53
Rebuilds the SharePoint configuration cache on the specified servers in parallel.
#Requires -Version 4.0
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop
$serverNames = Get-SPServer | ? { $_.Role -ne "Invalid" } | % { $_.Address }
workflow Repair-ConfigCache
{
param
(
[parameter(Mandatory=$true)][string[]]$ComputerNames,
@joerodgers
joerodgers / Update-SiteClassificationFromExistingWebProperty.ps1
Last active November 2, 2017 19:42
This script will sync a web property bag value to the Site.Classification property on all SPO sites in the tenant.
Add-Type -Path "C:\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.Online.SharePoint.Client.Tenant.dll"
$tenantAdminUrl = "https://contoso-admin.sharepoint.com"
$tenantAdminUsername = "admin@contoso.onmicrosoft.com"
$securePassword = ConvertTo-SecureString 'pass@word1' -AsPlainText -Force
$script:PropertyName = "contoso_SiteDataClassification"
@joerodgers
joerodgers / Get-NestedGroupMembership.ps1
Created November 3, 2017 13:09
Gets all user principals (including nested group memberships) from an Active Directory Group
function Get-NestedGroupMembership
{
[cmdletbinding()]
param
(
[parameter(Mandatory=$true)][string]$Cn
)
begin
{
@joerodgers
joerodgers / Upload-FileToSharePointLibrary.ps1
Created November 3, 2017 13:13
Uploads a file(s) to a SharePoint 2010+ document library using CSOM
Add-Type -Path "E:\14_assemblies\Microsoft.SharePoint.Client.dll"
Add-Type -Path "E:\14_assemblies\Microsoft.SharePoint.Client.Runtime.dll"
function Upload-FileToSharePointLibrary
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)][string]$SharePointWebUrl,
[Parameter(Mandatory=$true)][string]$DocumentLibraryName,
@joerodgers
joerodgers / DatabaseAvailabilityGroupMgmt.ps1
Created November 3, 2017 14:01
Examples on how to add and remove SQL Server databases from a SQL Server Availability Group
#Requires -Version 3.0
function Invoke-NonQuery
{
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)][string]$DatabaseName,
[Parameter(Mandatory=$true)][string]$DatabaseServer,
[Parameter(Mandatory=$true)][string]$Query,
[int]$CommandTimeout=30 # The default is 30 seconds
@joerodgers
joerodgers / New-TokenSigningCertificate.ps1
Last active November 7, 2018 14:24
Creates a new self-signed SSL certificate that can be used as a token signing certificate in provider hosted apps (add-ins) configuration. This script must be run on a SharePoint server, it relies makecert.exe that is installed by SharePoint.
function New-TokenSigningCertificate
{
[CmdletBinding()]
param
(
[parameter(Position=0, Mandatory=$true)][string]$CertificateName,
[parameter(Position=0, Mandatory=$true)][string]$Path,
[parameter(Position=0, Mandatory=$true)][string]$CertificateDomain,
[parameter(Position=0, Mandatory=$true)][string]$Password
)
@joerodgers
joerodgers / New-ProviderHostedAppRegistration.ps1
Created November 3, 2017 17:57
Registers a new provider hosted app with the Security Token Service
function New-ProviderHostedAppRegistration
{
[CmdletBinding()]
param
(
[parameter(Position=0, Mandatory=$true)][System.Security.Cryptography.X509Certificates.X509Certificate2]$TokenSigningCertificate,
[parameter(Position=0, Mandatory=$true)][string]$TrustedRootAuthorityDisplayName,
[parameter(Position=0, Mandatory=$true)][string]$SPTrustedSecurityTokenIssuerDisplayName,
[parameter(Position=0, Mandatory=$false)][System.Guid]$IssuerId
)
@joerodgers
joerodgers / YammerAdministrator.ps1
Last active October 3, 2023 17:56
Example PowerShell functions for the administration of Yammer users and groups
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$clientId = $env:YammerClientId
$accessToken = $env:YammerAccessToken
function Get-ResponseFailureInfo
{
[cmdletbinding()]
param
@joerodgers
joerodgers / Test-FolderPath.ps1
Last active November 9, 2017 22:56
Tests a NTFS directory structure to find files and folders that will fail to upload to a SharePoint on-prem document library because of file name length, file path length, file size or file extensions restrictions.
function Test-FolderPath
{
<#
.Synopsis
This function scans a NTFS directory for file and folder length violations against the URL path length restrictions outlined in
the "URL path length restrictions (SharePoint Server 2010)" technet article. The script will create up to three .csv files,
each containing respective violation types. The script will also create a fourth .csv that contains all files that will be
blocked on upload due to file extension.