Skip to content

Instantly share code, notes, and snippets.

View theknoxtech's full-sized avatar

Jon Witherspoon theknoxtech

View GitHub Profile
@theknoxtech
theknoxtech / Restart_as_Admin.ps1
Last active May 25, 2026 20:48
Restart PowerShell Script as Admin
<#
This snippet will restart a powershell script and use the same powershell host that was used initially 5.1 or Core
#>
If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$PSHost = If ($PSVersionTable.PSVersion.Major -le 5) {'PowerShell'} Else {'PwSh'}
Start-Process -Verb RunAs $PSHost (@(' -NoExit')[!$NoExit] + " -File `"$PSCommandPath`" " + ($MyInvocation.Line -split '\.ps1[\s\''\"]\s*', 2)[-1])
Break
}
<#
.SYNOPSIS
This script recursively gets archive information regarding each mailbox in a M365 tenant
.DESCRIPTION
This gathers the following information about each user mailbox in an M365 tenant. Optional export to csv is available
Display Name