Saturday, February 17, 2024

Powershell script to check B2B guest account invitation state in bulk

 # Install AzureAD module if not already installed

Install-Module -Name AzureAD -Force -Scope CurrentUser

# Import required modules

Import-Module AzureAD

# Read emails from Excel sheet

$emails = Import-Excel -Path "emails.xlsx" | Select-Object -ExpandProperty Email

# Connect to Azure AD

Connect-AzureAD

# Iterate through emails and check user existence and account status

foreach ($email in $emails) {

    $user = Get-AzureADUser -Filter "mail eq '$email'"

    if ($user) {

        Write-Host "User with email $email exists. Account Enabled: $($user.AccountEnabled) with invitation status: $($user.UserState)"

    } else {

        Write-Host "User with email $email does not exist."

    }

}


No comments:

Post a Comment