Skip to content

Instantly share code, notes, and snippets.

View Sync-TeamsAppPermissionPolicyMembers.ps1
#requires -Modules MicrosoftTeams, Microsoft.Graph.Groups, Microsoft.PowerShell.SecretManagement, Microsoft.PowerShell.SecretStore
function Split-Array
{
[cmdletbinding()]
param
(
[Parameter(Mandatory=$true)]
[object[]]$Array,
[Parameter(Mandatory=$true)]
@joerodgers
joerodgers / New-MetalogixActiveConnectionXMLFile.ps1
Last active Jul 30, 2021
Generates an ActiveConnections.xml file that can be used by the Metalogix Content Matrix Console. This script must be run from the server hosting the console and run as the user running the Metalogix service since the password encryption is machine and user specific.
View New-MetalogixActiveConnectionXMLFile.ps1
$assemblyPath = "C:\Program Files (x86)\Metalogix\Content Matrix Consoles\SharePoint Edition\Metalogix.Core.dll"
$tenantAdminSiteUrl = "https://contoso-admin.sharepoint.com"
$migrationAccounts = @{
'john.doe@contoso.com' = 'pass@word1'
'jane.doe@contoso.com' = 'pass@word2'
}
Add-Type -Path $assemblyPath
@joerodgers
joerodgers / Password-Encryption.ps1
Last active Jul 30, 2021
Examples of how to encrypt/decrypt strings using a X509Certificate2 certificate.
View Password-Encryption.ps1
function ConvertTo-PlaintextString
{
[CmdletBinding()]
param
(
[parameter(Mandatory=$true)][string]$EncryptedPassword,
[parameter(Mandatory=$true)][System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate
)
begin
@joerodgers
joerodgers / settings.json
Created Jul 14, 2021
Visual Studio Code Settings Change to allow double clicking variable that includes the "$" value. File location: "%AppData%\Roaming\Code\User\settings.json
View settings.json
{
"powershell.powerShellDefaultVersion": "PowerShell (x64)",
"powershell.codeFormatting.autoCorrectAliases": true,
"powershell.codeFormatting.useCorrectCasing": true,
"powershell.codeFormatting.whitespaceBetweenParameters": true,
"powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationAfterEveryPipeline",
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.openBraceOnSameLine": false,
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
@joerodgers
joerodgers / Get-OneDriveForBusinessSiteOwnerObjectId.ps1
Last active Jul 28, 2021
This script will create a report containing OD4B sites and the value of the AadObjectId stored in SharePoint and Azure Active Directory. This data can be used to help detect PUID mismatches of OD4B site owners.
View Get-OneDriveForBusinessSiteOwnerObjectId.ps1
#Requires -Module PnP.PowerShell
function Get-OneDriveForBusinessSiteOwnerObjectId
{
[CmdletBinding()]
param
(
# OneDrive Site Url
[Parameter(Mandatory=$false)]
[string]
@joerodgers
joerodgers / Get-TenantIdByDomainName.ps1
Created Jul 1, 2021
Get's the TenantId (and other info) from the domain name
View Get-TenantIdByDomainName.ps1
$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 / Invoke-LogicAppDeployment.ps1
Last active Jul 1, 2021
Site Directory Logic App Template and Deployment
View Invoke-LogicAppDeployment.ps1
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
Login-AzAccount
$parameters = @{
objectId = (Get-AzADUser -UserPrincipalName (Get-AzContext).Account).Id
clientId = $env:O365_CLIENTID
clientSecret = $env:O365_CLIENTSECRET
}
@joerodgers
joerodgers / Download-SFTPFile.ps1
Created Jun 28, 2021
Example of how to download a file using Posh-SSH via SSH/SFTP
View Download-SFTPFile.ps1
#requires -Modules Posh-SSH
$hostname = "server.contoso.com"
$keyFile = "C:\_temp\ssh-key.pem"
$userName = "johndoe"
$certPassword = ConvertTo-SecureString -String 'password' -AsPlainText -Force
$localPath = "c:\_temp\file.dat"
$remotePath = "/folder1/folder2/folder3"
$remoteFile = "file.dat"
View Export-ContentDatabaseMappingsToCsv.ps1
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
$timestamp = Get-Date -Format FileDateTime
# Using Get-SPWebApplication here b/c Get-SPContentDatabase does not return databases that are not "online"
Get-SPWebApplication | SELECT -ExpandProperty ContentDatabases | SELECT @{ Name="WebApplicationUrl"; Expression={ $_.WebApplication.Url }}, Name, Server, WarningSiteCount, MaximumSiteCount, Status | Export-Csv "E:\_temp\DatabaseMappings_$timestamp.csv" -NoTypeInformation
@joerodgers
joerodgers / Get-MicrosoftGraphActivityDetailReports.ps1
Last active Jun 23, 2021
Automates the retrieval of several reports about SharePoint and Group Usage from the Microsoft Graph API
View Get-MicrosoftGraphActivityDetailReports.ps1
#requires -Modules SharePointPnPPowerShellOnline
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
function Get-Office365GroupsActivityDetailReport
{
[CmdletBinding()]
param