Skip to content

Instantly share code, notes, and snippets.

@joerodgers
joerodgers / Add-CodeDomAuthorizedType.ps1
Last active January 4, 2023 13:36
Adds the necessary authorizedType elements in the WEB.CONFIG and OWSTIMER.EXE.CONFIG on SharePoint servers
<#
This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
We grant you a nonexclusive, royalty-free right to use and modify the sample code and to reproduce and distribute the object
code form of the Sample Code, provided that you agree:
(i) to not use our name, logo, or trademarks to market your software product in which the sample code is embedded;
(ii) to include a valid copyright notice on your software product in which the sample code is embedded; and
(iii) to indemnify, hold harmless, and defend us and our suppliers from and against any claims or lawsuits, including
@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 / 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 / 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 / Select-PowerShellScriptString.ps1
Created October 23, 2017 18:45
Search all PowerShell Scripts in a Directory (and sub-directories) for a Specific String
$pattern = "Get-SPSite"
$path = "C:\_scripts\SharePoint\OnPrem"
$files = Get-ChildItem -Path $path -Recurse -Include "*.ps1", "*.psm1"
$scanned = @()
foreach( $file in $files )
@joerodgers
joerodgers / Add-FormsAuthRequestHeader.ps1
Created October 9, 2017 17:38
Allow SPO CSOM and Microsoft.SharePoint.PowerShell PSSnapIn to Coexist in the same AppDomain
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
# prevent issues with the SharePoint API certificate validation procedures (must be after loading sharepoint snapin)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
function Add-FormsAuthRequestHeader
{
   param
(
[Parameter(Mandatory=$true)][Object]$ClientContext
@joerodgers
joerodgers / Set-SPOSiteNoCrawl.ps1
Created October 6, 2017 20:31
Set the "NoCrawl" Attribute on the the RootWeb of an SPO Site Collection
# https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM
Add-Type -Path "C:\O365_CSOM\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\O365_CSOM\Microsoft.SharePointOnline.CSOM.16.1.6008.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll"
$credential = Get-Credential -Message "SharePoint Online Site Administrator"
$context = New-Object Microsoft.SharePoint.Client.ClientContext( "https://contoso.sharepoint.com/sites/teamsite" )
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)
$context.Load($context.Site.RootWeb.AllProperties)
@joerodgers
joerodgers / Get-Office365UrlandIPAddressUpdates
Created October 5, 2017 19:49
Download the latest O365 URL and IP Address Updates to a CSV
function Get-Office365UrlandIPAddressUpdates
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$false)][int]$Days = -7
)
begin
@joerodgers
joerodgers / Enable-HtmlDesignFeature.ps1
Created September 26, 2017 17:23
Enable and/or Report on the SPWeb Property Settings Related to the HTMLDesign Feature on an SPO Site
$site = "https://contoso.sharepoint.com/sites/publishing-site"
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"
function Get-HtmlDesignFeatureProperties
{
[cmdletbinding()]
param
@joerodgers
joerodgers / Get-SMATUnsupportedWebTemplateDetail.ps1
Created September 26, 2017 17:13
Get SharePoint Migration Assessment Tool (SMAT) Unsupported Web Template SPWeb Details
$results = @()
Get-SPSite -Limit All | ? { -not $_.IsReadLocked } | Get-SPWeb -Limit All | ? { -not $_.IsAppWeb } | % {
if( $_.webTemplate -ne "STS" -and $_.WebTemplate -ne "SPSPERS" )
{
$totalItemCount = 0
# total the item counts in all the visible lists
$_.Lists | ? { -not $_.Hidden } | % { $totalItemCount += $_.ItemCount }