Skip to content

Instantly share code, notes, and snippets.

@joerodgers
joerodgers / Get-AADUserLicenseInfo.ps1
Created September 11, 2017 18:11
Get-AADUserLicenseInfo.ps1
<#
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;
@joerodgers
joerodgers / postListDataToRemoteService.js
Last active September 26, 2017 17:17
Post List Data to Remote Service
<script type="text/javascript">
function PreSaveAction() // native sharepoint method for data validation
{
if( $('input[title="Post to External Service"]')[0].checked )
{
var data = getData();
console.log(data);
@joerodgers
joerodgers / Download-FileFromSPO.ps1
Last active May 4, 2023 06:17
Download a File From SharePoint Online Document Library
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"
function Download-File
{
[cmdletbinding()]
param
(
[Parameter(Mandatory=$true)][Microsoft.SharePoint.Client.ClientContext]$ClientContext,
[Parameter(Mandatory=$true)][System.Uri]$FileUri,
@joerodgers
joerodgers / ConvertTo-CsvFromExcelWorksheet.ps1
Last active September 26, 2017 17:16
Export Excel Worksheet to CSV
function ConvertTo-CsvFromExcelWorksheet
{
[cmdletbinding()]
param
(
[Parameter(Mandatory=$true)][string]$ExcelFilePath,
[Parameter(Mandatory=$true)][string]$CsvFilePath,
[Parameter(Mandatory=$false)][string]$Worksheet = "Sheet1"
)
@joerodgers
joerodgers / Get-ListsWithOver5kItems.ps1
Created September 22, 2017 18:57
Display all lists in a SharePoint 2013+ farm that have >5k items
Get-SPSite -Limit All | Get-SPWeb -Limit All | ? { -not $_.IsAppWeb } | % {
foreach( $list in $_.Lists )
{
if( $list.ItemCount -gt 5000 )
{
[PSCustomObject] @{
WebUrl = $list.ParentWeb.Url
List = $list.Title
ListUrl = $list.ParentWeb.Site.MakeFullUrl($list.DefaultViewUrl)
@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 }
@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-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 / 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 / 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