Skip to content

Instantly share code, notes, and snippets.

View SpectreConsoleTable.psm1
function New-SpectreConsoleTable
{
return New-Object Spectre.Console.Table
}
function New-SpectreConsoleTableColumn
{
[CmdletBinding()]
param
(
@joerodgers
joerodgers / redirectmap.config
Last active May 17, 2022
Azure App Service URL Redirect web.config and redirectmap.config examples
View redirectmap.config
<rewriteMaps>
<rewriteMap name="businesssolutions">
<add key="sites/123" value="sites/123"/>
<add key="sites/abc" value="sites/abc"/>
<add key="sites/abc123" value="sites/abc123"/>
</rewriteMap>
<rewriteMap name="diversifiedbusiness">
<add key="sites/123" value="sites/123"/>
<add key="sites/abc" value="sites/abc"/>
<add key="sites/abc123" value="sites/abc123"/>
@joerodgers
joerodgers / Get-SiteCollectionUserInformationListPrincipal.ps1
Last active May 13, 2022
Exports basic information about all user and group principals on a site collection in SPO/OD4B, specifically if the principal exists in Azure Active Directory.
View Get-SiteCollectionUserInformationListPrincipal.ps1
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
function Get-SiteCollectionUserInformationListPrincipal
{
[CmdletBinding()]
param
@joerodgers
joerodgers / Invoke-ListPermissionInheritanceReset.ps1
Last active May 11, 2022
Script to reset permission inheritance on lists in a site collection in SharePoint Online.
View Invoke-ListPermissionInheritanceReset.ps1
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
function Invoke-FolderPermissionInheritanceReset
{
[CmdletBinding()]
param
(
View Initialize-SiteCollectionSubWebHierarchy.ps1
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$targetSiteUrl = "https://contoso.sharepoint.com/sites/teamsite"
$sourceSiteUrl = "https://sharepoint.2019.contoso.lab/sites/teamsite"
$tenantName = $env:O365_TENANT
$clientId = $env:O365_CLIENT_ID
$certificateThumbprint = $env:O365_THUMBPRINT
@joerodgers
joerodgers / Invoke-SharePointUnifiedAuditLogSearch.ps1
Created Apr 14, 2022
Example how to search the unified audit log for SharePoint
View Invoke-SharePointUnifiedAuditLogSearch.ps1
#requires -modules "ExchangeOnlineManagement"
[System.Net.Http.HttpClient]::DefaultProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
function Invoke-SharePointUnifiedAuditLogSearch
{
[CmdletBinding()]
param
(
@joerodgers
joerodgers / Disable-SharingForNonOwnersOfSite.ps1
Created Mar 29, 2022
Example of how to call DisableSharingForNonOwnersOfSite via REST API
View Disable-SharingForNonOwnersOfSite.ps1
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$clientId = $env:O365_CLIENTID
$thumbprint = $env:O365_THUMBPRINT
$tenantId = $env:O365_TENANTID
$tenant = $env:O365_TENANT
@joerodgers
joerodgers / Get-TenantSiteOwners.ps1
Last active Apr 15, 2022
Reports all tenant site data and expands all M365 Group owners
View Get-TenantSiteOwners.ps1
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$clientId = $env:O365_CLIENTID
$thumbprint = $env:O365_THUMBPRINT
$tenant = $env:O365_TENANT
$includeSCA = $true
@joerodgers
joerodgers / Get-SPOSiteIdByUrlViaRest.ps1
Created Mar 17, 2022
Couple options for looking up a site collection's id value via REST API
View Get-SPOSiteIdByUrlViaRest.ps1
Connect-PnPOnline `
-Url "https://$($env:O365_TENANT)-admin.sharepoint.com" `
-ClientId $env:O365_CLIENTID `
-Thumbprint $env:O365_THUMBPRINT `
-Tenant $env:O365_TENANTID
$response = Invoke-PnPSPRestMethod `
-Method POST `
-Url "/_api/web/lists/GetByTitle('DO_NOT_DELETE_SPLIST_TENANTADMIN_ALL_SITES_AGGREGATED_SITECOLLECTIONS')/GetItems(query=@v1)?@v1={ `"ViewXml`" : `"<View><Query><Where><Eq><FieldRef Name='SiteUrl'/><Value Type='TEXT'>https://$($env:O365_TENANT).sharepoint.com/sites/teamsite</Value></Eq></Where></Query><ViewFields><FieldRef Name='SiteUrl'/><FieldRef Name='SiteId'/></ViewFields></View>`" }" `
-Content "" `
@joerodgers
joerodgers / New-OneDriveFolderReport.ps1
Created Mar 15, 2022
Generates a CSV file that reports the existing of the documents, pictures and desktop folders existence in all onedrives in the tenant.
View New-OneDriveFolderReport.ps1
#requires -modules "Microsoft.Graph.Authentication", "Microsoft.Graph.Sites"
# required service principal permissions
# Graph > Application > Files.Read.All
# Graph > Application > Sites.Read.All
Connect-MgGraph `
-ClientId $env:O365_CLIENTID `
-CertificateThumbprint $env:O365_THUMBPRINT `
-TenantId $env:O365_TENANTID | Out-Null