Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Connect to Microsoft Graph
- $tenantId = "TENANT ID"
- Connect-MgGraph -TenantId $tenantId -Scopes "User.Read.All"# Import the CSV file containing the primary email addresses and aliases
- $users = Import-Csv -Path "recipients.csv"# Initialize an array to hold the results
- $results = @()# Check each user for a personal Microsoft account and output the result
- foreach ($user in $users) {
- # Check the primary email address
- $primaryEmail = $user.PrimarySMTPAddress
- $primaryResult = Get-MsIdHasMicrosoftAccount -Mail $primaryEmail
- $results += [PSCustomObject]@{
- UserEmail = $primaryEmail
- HasPersonalMicrosoftAccount = $primaryResult
- }
- # Check each alias
- $aliases = $user.Aliases -split ","
- foreach ($alias in $aliases) {
- if ($alias -ne "-" -and ![string]::IsNullOrWhiteSpace($alias)) {
- $aliasResult = Get-MsIdHasMicrosoftAccount -Mail $alias
- $results += [PSCustomObject]@{
- UserEmail = $alias
- HasPersonalMicrosoftAccount = $aliasResult
- }
- }
- }
- }# Export the results to a CSV file
- $results | Export-Csv -Path "personalMicrosoftAccountsCheck.csv" -NoTypeInformation -Encoding UTF8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement