Skip to content

Instantly share code, notes, and snippets.

#requires -modules "PnP.PowerShell"
function Get-TenantInformation
{
[cmdletbinding()]
param
(
)
$response = Invoke-PnPSPRestMethod -Method "Get" -Url "/_api/TenantInformationCollection"
#requires -modules "Microsoft.Graph.Authentication", "Microsoft.Graph.Teams", "Microsoft.Graph.Users"
# context requires Microsoft Graph application permissions: User.Read.All + AppCatalog.Read.All
Connect-MgGraph `
-ClientId $env:CDX_CLIENTID `
-CertificateThumbprint $env:CDX_THUMBPRINT `
-TenantId $env:CDX_TENANTID `
-ErrorAction Stop
$skuId = "06ebc4ee-1bb5-47dd-8120-11324bc54e06" # Microsoft 365 E5
@joerodgers
joerodgers / Invoke-LongRunningTaskWithSqlLiteStorage.ps1
Created April 11, 2025 14:10
mockup framework on how you could use SQLite database to track progress and store results for long running (days) scripts. This would allow for a script to be restarted from where it failed rather than having to start all the sites over.
Import-Module -Name PSSQLite
function Initialize-Database
{
[CmdletBinding()]
param
(
[parameter(mandatory=$true)]
[string]
$Path,
@joerodgers
joerodgers / Get-RecordingFileAnalytics.ps1
Last active April 8, 2025 13:31
Reports Teams recordings (.mp4) analytics in all onedrives
#requires -Modules @{ ModuleName="PnP.PowerShell"; ModuleVersion="2.4.0" }
function New-Recording
{
[CmdletBinding()]
param
(
[parameter(mandatory=$true)]
[AllowEmptyString()]
[string]
@joerodgers
joerodgers / Block-3rdPartyCopilotTeamsApps.ps1
Created March 31, 2025 15:57
Uses the app export file from the TAC to block all Copilot specific 3rd party apps from the Teams app store.
Connect-MicrosoftTeams
$rows = Import-Csv -Path "C:\_temp\manageAppsPage_manageAppsList_3-31-2025.csv"
foreach( $row in $rows )
{
if( $row.'Supported on' -notmatch "Copilot" )
{
continue
}
#requires -modules "Microsoft.Graph.Authentication"
function Get-TeamsMeetingId
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[Guid]
$UserObjectId,
@joerodgers
joerodgers / New-VivaInsightsManagerHierarchyCsv.ps1
Last active March 14, 2025 21:00
Generates a .csv file which can be uploaded to Viva Insights for custom reporting based on manager reporting chain.
#requires -modules "Microsoft.Graph.Authentication", "Microsoft.Graph.Users"
function Get-ManagerHierarchy
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[string]
$Identity
@joerodgers
joerodgers / Restore-SPOSitesBySiteId.ps1
Created March 6, 2025 21:58
Restores a list of sites in the recycle bin by SiteId
#requires -modules "pnp.powershell"
# requires SharePoint > Application > Sites.FullControl.All
Connect-PnPOnline -Url "https://$env:CDX_TENANT-admin.sharepoint.com" `
-ClientId $env:CDX_CLIENTID `
-Thumbprint $env:CDX_THUMBPRINT `
-Tenant $env:CDX_TENANTID `
-ErrorAction Stop
@joerodgers
joerodgers / Get-SharePointSpacePageViewAnalytics.ps1
Created March 5, 2025 21:08
Locates all SharePoint Spaces pages and reports the page Url and all time view analytics for the page.
#requires -modules "Pnp.PowerShell"
Connect-PnPOnline -Url "https://$env:CDX_TENANT-admin.sharepoint.com" `
-ClientId $env:CDX_CLIENTID `
-Thumbprint $env:CDX_THUMBPRINT `
-Tenant $env:CDX_TENANTID `
-ErrorAction Stop
# Get all site collections
$sites = Get-PnPTenantSite -Filter "LockState -eq 'Unlock'"
# requires Microsoft Forms > Application > Forms.Read.All
Connect-PnPOnline -Url "https://$env:CDX_TENANT-admin.sharepoint.com" `
-ClientId $env:CDX_CLIENTID `
-Thumbprint $env:CDX_THUMBPRINT `
-Tenant $env:CDX_TENANTID `
-ErrorAction Stop
$userObjectId = "a8734c7e-a19b-41c6-b384-........"
$formId = "pVQHEDt5kk....."