Skip to content

Instantly share code, notes, and snippets.

View JoeAlanis's full-sized avatar

Joe Alanis [MSFT] JoeAlanis

View GitHub Profile
@joerodgers
joerodgers / automate details.md
Last active July 24, 2023 16:05
Overview of a Power Automate flow that triggers an Azure Function to translate the contents of a site page to a new language

Language Formala:

@{replace(replace(triggerOutputs()?['body/{Path}'],'SitePages/', ''),'/','')}

Overview: powerautomate

@joerodgers
joerodgers / Get-ApplicationsWithCertOrSecretExpirations.ps1
Last active June 12, 2025 13:38
Gets all Azure AD Applications that have client secrets or certificates expiring on or before the provided expiration date.
#requires -Modules @{ ModuleName="Microsoft.Graph.Authentication"; ModuleVersion="2.0.0" }
#requires -Modules @{ ModuleName="Microsoft.Graph.Applications"; ModuleVersion="2.0.0" }
function Get-ApplicationWithExpiratingClientSecret
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true)]
@joerodgers
joerodgers / Get-SPOTenantAdminStorageQuotas.ps1
Created January 3, 2022 19:23
REST API that returns the storage quota information for an SPO tenant
Connect-PnPOnline -Url "https://tenant-admin.sharepoint.com" -ClientId $env:O365_CLIENTID -Thumbprint $env:O365_THUMBPRINT -Tenant $env:O365_TENANTID
Invoke-PnPSPRestMethod -Method Get -Url "https://tenant-admin.sharepoint.com/_api/StorageQuotas()?api-version=1.3.2" | Select-Object -ExpandProperty value
GeoAllocatedStorageMB : 0
GeoAvailableStorageMB : 2828400
GeoLocation : NAM
GeoUsedStorageMB : 12176
QuotaType : 0
TenantStorageMB : 2840576
@joerodgers
joerodgers / Password-Encryption.ps1
Last active September 9, 2021 16:46
Examples of how to encrypt/decrypt strings using a X509Certificate2 certificate.
function ConvertTo-PlaintextString
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true)][string]$EncryptedPassword,
[parameter(Mandatory=$true)][System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate
)
begin
@joerodgers
joerodgers / Get-TenantIdByDomainName.ps1
Created July 1, 2021 19:25
Get's the TenantId (and other info) from the domain name
$domain = "contoso.com"
Invoke-WebRequest -Uri "https://login.windows.net/$domain/v2.0/.well-known/openid-configuration" | ConvertFrom-Json
<#
token_endpoint : https://login.windows.net/1316cd1f-b0c7-4253-a7f3-ccc9041aaag9/oauth2/v2.0/token
token_endpoint_auth_methods_supported : {client_secret_post, private_key_jwt, client_secret_basic}
jwks_uri : https://login.windows.net/1316cd1f-b0c7-4253-a7f3-ccc9041aaag9/discovery/v2.0/keys
response_modes_supported : {query, fragment, form_post}
subject_types_supported : {pairwise}
@joerodgers
joerodgers / Clone-RoleAssignmentForPrincipal.ps1
Created October 4, 2018 13:52
Script will clone a user or group principal's permissions to a new user or group principal.
# .\nuget.exe install Microsoft.SharePoint.Client
Add-Type -Path "C:\Microsoft.SharepointOnline.CSOM.16.1.8029.1200\lib\net45\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Microsoft.SharepointOnline.CSOM.16.1.8029.1200\lib\net45\Microsoft.SharePoint.Client.Runtime.dll"
# .\nuget.exe install Microsoft.IdentityModel.Clients.ActiveDirectory
Add-Type -Path "C:\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
Add-Type -Path "C:\Microsoft.IdentityModel.Clients.ActiveDirectory.3.19.2\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
@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 / Set-SPListVersionHistoryLimits.ps1
Created July 16, 2018 13:09
Updates the major and minor version limits for a document library. Optionally allows you to prune versions over the specified version settings.
Add-PSSnapin Microsoft.SharePoint.PowerShell
<#
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
@joerodgers
joerodgers / Get-WokflowAssociationAndInstanceInfo.ps1
Created May 10, 2018 17:45
Script will get all workflow associations on an SPO web and all Workflow Manager workflow instances on an SPO web. The script has the ability to recursively traverse all webs in a site collection.
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.SharePoint.Client.WorkflowServices.dll"
function New-ClientContext
{
[cmdletbinding()]
param
(
[Parameter(Mandatory=$true)][System.Uri]$Uri,
@joerodgers
joerodgers / Add-TopBannerBar.ps1
Last active August 30, 2018 17:43
Script will add a custom message banner across the top a site or web.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
function Remove-CustomAction
{
param
(
[parameter(Mandatory=$true, ParameterSetName='Site')]
[Microsoft.SharePoint.SPSite]$Site,
[parameter(Mandatory=$true, ParameterSetName='Web')]