Skip to content

Instantly share code, notes, and snippets.

#requires -modules "PnP.PowerShell"
# requires SharePoint > application > sites.fullcontrol.all permissions
$sites = "https://m365cpi68930152.sharepoint.com/sites/security-policies1",
"https://m365cpi68930152.sharepoint.com/sites/security-policies2"
$timestamp = Get-Date -Format FileDateTime
foreach( $site in $sites )
#requries -modules "Microsoft.PowerApps.Administration.PowerShell"
function Get-AuthorizationHeader
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[string]
$EnvironmentUrl
@joerodgers
joerodgers / UserProfilePropertyCache.yaml
Created October 14, 2025 15:13
Example Copilot Studio Topic showing how to cache User Profile properties in a global record variable for 24 hours
kind: AdaptiveDialog
beginDialog:
kind: OnActivity
id: main
condition: =DateDiff(DateAdd(Coalesce(Global.UserProfile.LastRefreshed,Now()), 1440, TimeUnit.Minutes), Now(),TimeUnit.Minutes) > 0
type: Message
actions:
- kind: BeginDialog
id: 0FnaSJ
input: {}
@joerodgers
joerodgers / Test-VNETAppInsightsConnectivity.ps1
Last active November 5, 2025 17:50
Example script for testing DNS and connectivity to the Application Insights from a Power Platform environment connected to a customer managed Azure subnet via enterprise policy
Import-Module -Name "Microsoft.PowerPlatform.EnterprisePolicies" -ErrorAction Stop
Connect-AzAccount
$tenantId = "<YOUR TENANT ID>"
$environmentId = "<ENVIRONMENT ID>"
$hostname = "dc.services.visualstudio.com"
Test-DnsResolution `
-EnvironmentId $environmentId `
# taken from -- https://www.powershellgallery.com/packages/AzurePowerShellUtilityFunctions
function Send-AppInsightsEventTelemetry
{
<#
.SYNOPSIS
Sends custom event telemetry to an Azure Application Insights instance.
.DESCRIPTION
Sends custom event telemetry to an Azure Application Insights instance. This function uses the Azure Application Insights REST API instead of a compiled client library, so it works without additional dependencies.
@joerodgers
joerodgers / Add-CopilotStudioSharePointSSOAppCustomizer.ps1
Last active September 30, 2025 14:38
Example script that deploys the SharePointSSOAppCustomizer SPFx solution to the tenant catalog and then adds an instance to a single SPO site
#requires -modules "PnP.PowerShell"
# example script for deploying the following to an spo site
# https://github.com/microsoft/CopilotStudioSamples/tree/main/SSOSamples/SharePointSSOAppCustomizer
# requires Sites.FullControl.All or SharePoint Administrators role
Connect-PnPOnline -Url "https://$env:CDX_TENANT.sharepoint.com/sites/Copilot-Studio-Agent" `
-ClientId $env:CDX_CLIENTID `
-Thumbprint $env:CDX_THUMBPRINT `
-Tenant $env:CDX_TENANTID
@joerodgers
joerodgers / Uninstall-AzModules.ps1
Created September 26, 2025 16:11
Uninstalls all versions of the Az modules
Get-InstalledModule -Name Az.* | ForEach-Object -Process { Get-InstalledModule -Name $_.Name -AllVersions | Uninstall-Module -Force -Verbose }
Get-InstalledModule -Name Az -AllVersions | Uninstall-Module -Force -Verbose
@joerodgers
joerodgers / Get-PowerPlatformEnvironmentSubnetIPUsage.ps1
Last active September 30, 2025 17:54
Reports the number of IP addresses consumed for each Power Platform environment that is associated with an enterprise policy. Remember to add 5 additional IP addresses to the total per unique subnet.
Import-Module -Name "Microsoft.PowerPlatform.EnterprisePolicies" -ErrorAction Stop
Import-Module -Name "Microsoft.PowerApps.Administration.PowerShell" -ErrorAction Stop
# connect to az and power platform as user with the Power Platform Admin role
Add-PowerAppsAccount -ErrorAction Stop
Connect-AzAccount -ErrorAction Stop | Out-Null
# get all environments with an enterprise policy applied
@joerodgers
joerodgers / Get-EnvironmentAgentMessageConsumptionReport.ps1
Last active September 19, 2025 15:36
Reports agent Copilot Credit consumption per agent per environment.
#requires -modules "Microsoft.PowerApps.Administration.PowerShell"
function Get-FirstDayOfMonthDate
{
[CmdletBinding()]
param
(
)
$month = [DateTime]::Today.Month
@joerodgers
joerodgers / Get-QuickXorHash.ps1
Created August 28, 2025 14:59
Generates the QuickXorHash value of a local file.
# Credit belongs to https://mgwdevcom.wordpress.com/2025/06/09/verifying-sharepoint-file-integrity-with-quickxorhash-in-powershell/
# made small updates to support PowerShell 5.1
function Get-QuickXorHash
{
param
(
[Parameter(Mandatory = $true)]
[string]
$FilePath