Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krzydoug/8a90a426c183505fe678b1a8f3399516 to your computer and use it in GitHub Desktop.
Save krzydoug/8a90a426c183505fe678b1a8f3399516 to your computer and use it in GitHub Desktop.
# Define the functions
function RevokeRefreshToken
{
$azureADConnected = ConnectToAzureAD
if($azureADConnected -eq $true)
{
$userInput = Read-Host "Press 1 to specify csv file or enter an email address of a specific user"
if($userInput.Equals("1"))
{
$csvPath = Read-Host "Enter the path of the csv (CSV data should have the email address example@domain.com)"
if(!(Test-Path -Path $csvPath))
{
Write-Host "$csvPath is invalid"
}
else
{
Import-Csv $csvPath | ForEach-Object { ($_.Email) | Revoke-AzureADUserAllRefreshToken }
}
}
else
{
Write-Host "Removing refresh token for $userInput"
Get-AzureADUser -SearchString "$userInput" | Revoke-AzureADAllRefreshToken
}
}
}
function ConnectToAzureAD
{
try
{
Get-InstalledModule -Name "AzureAD" -ErrorAction Stop
Write-Host "Azure AD module found...connecting to AzureAD"
Connect-AzureAD -ErrorAction Continue
$azureADConnected = $true
}
catch
{
$azureADConnected = $false
}
Write-Host "$azureADConnected"
$azureADConnected
}
# Script start
RevokeRefreshToken
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment