Skip to content

Instantly share code, notes, and snippets.

@joerodgers
joerodgers / Get-TranscriptFile.ps1
Last active April 25, 2024 20:30
Rough proof of concept on locating transcript files stored in OD4B.
#requires -modules "PnP.PowerShell"
function Get-TranscriptFile
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[DateTime]
$CreatedOnOrBefore
@joerodgers
joerodgers / New-ConferenceRoomMailboxRunbook.ps1
Last active April 24, 2024 17:26
Automation Account Runbook POC for creating new conference room mailboxes based on submissions in a SPO list
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
Import-Module -Name "ExchangeOnlineManagement"
Import-Module -Name "PnP.PowerShell"
class MailboxRequest
{
[int]
$RequestId
@joerodgers
joerodgers / Get-KeyVaultSecret.ps1
Last active April 23, 2024 09:44
Example using REST and PowerShell to retrieve a secret from Azure Key Vault via AAD Service Principal credential
function Get-AccessToken
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true,ParameterSetName='Resource')]
[Parameter(Mandatory=$true,ParameterSetName='Scope')]
[string]$ClientId,
[Parameter(Mandatory=$true,ParameterSetName='Resource')]
@joerodgers
joerodgers / Grant-UserPermission.ps1
Last active April 16, 2024 20:14
Example of using the SP.Web.ShareObject REST endpoint to share a file or folder with a user email address.
#requries -modules "PnP.PowerShell"
function Get-PeoplePickerValueForEmail
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[string]
$Email
@joerodgers
joerodgers / Export-TenantAdminLists.ps1
Last active April 10, 2024 17:19
Exports the data from the hidden tenant admin site collection aggregated data to csv.
#requires -Modules PnP.PowerShell
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12
$tenant = $env:TENANT
$clientId = $env:CLIENTID
$thumbprint = $env:THUMBPRINT
$outputPath = $env:LOGDIRECTORY
@joerodgers
joerodgers / SharePointOnlineAppPrincipalCreation.md
Last active April 3, 2024 17:07
SharePoint Online App Principal Setup Instructions

SharePoint Online App Principal Creation

Create SharePoint App Prinicipal

  1. Create a new SharePoint App Principal by navigating to https://<tenant>.sharepoint.com/sites/<targetsite>/_layouts/15/appregnew.aspx. Click the Create buttons for both the Client Id and Client Secret fields. For automation tasks (PowerShell, .NET executables) you can enter generic information for the App Domain and Redirect URL fields.

2021-01-07_10-25-10

  1. Click the Create button.
@joerodgers
joerodgers / Get-ExternalUser.ps1
Last active April 3, 2024 16:55
Gets all External Users Assigned to a SPO/OD4B site in O365
#requires -modules "PnP.PowerShell"
[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
# connect to the tenant
Connect-PnPOnline `
-Url [https://$env:O365_TENANT-admin.sharepoint.com]https://$env:O365_TENANT-admin.sharepoint.com `
-ClientId $env:O365_CLIENTID `
@joerodgers
joerodgers / Update-LastLogonTimestamp.ps1
Created October 6, 2020 14:00
Trick to force an update to the LastLogon Timestamp for an Active Directory account. This is sometimes necessary for the portal cache accounts if a companies AD team disables accounts based on the LastLogon timestamp of a user.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function Update-LastLogonTimestamp
{
[CmdletBinding()]
param
(
[parameter(Position=0, Mandatory=$true)][string]$UserName
)
#requires -Modules @{ ModuleName="PnP.PowerShell"; ModuleVersion="1.12.0" }
function Find-SharedWithEveryoneOrEEEUContent
{
[CmdletBinding(DefaultParameterSetName="SharePoint")]
param
(
[Parameter(Mandatory=$true,ParameterSetName="SharePoint")]
[switch]
$IncludeSharePointOnline,