Skip to content

Instantly share code, notes, and snippets.

@AlLongley
Created November 19, 2023 02:32
Show Gist options
  • Save AlLongley/a15bf7a6faaf363f0d7a77c097b5f981 to your computer and use it in GitHub Desktop.
Save AlLongley/a15bf7a6faaf363f0d7a77c097b5f981 to your computer and use it in GitHub Desktop.
PowerShell Microsoft Graph/ExchangeOnline/API FUN
# There's no simple built-in equivalent of the powershell Get-AzAccessToken to dump the active Auth/Bearer/token
# from the session initiated with Connect-ExchangeOnline
# This dumps all active sessions in current PoSH context
[Microsoft.Exchange.Management.ExoPowershellSnapin.ConnectionContextFactory]::GetAllConnectionContexts() | ConvertTo-JSON
[Microsoft.Exchange.Management.ExoPowershellSnapin.ConnectionContextFactory]::GetAllConnectionContexts() | select PowerShellTokenInfo | ConvertTo-JSON
[Microsoft.Exchange.Management.ExoPowershellSnapin.ConnectionContextFactory]::GetAllConnectionContexts() | Where-Object {-not [System.String]::IsNullOrEmpty($_.PowerShellCredentials)} | select PowerShellTokenInfo | ConvertTo-JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment