Advertisement
Guest User

Untitled

a guest
Mar 13th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. # Connect to Microsoft Graph
  2. $tenantId = "TENANT ID"
  3. Connect-MgGraph -TenantId $tenantId -Scopes "User.Read.All"# Import the CSV file containing the primary email addresses and aliases
  4. $users = Import-Csv -Path "recipients.csv"# Initialize an array to hold the results
  5. $results = @()# Check each user for a personal Microsoft account and output the result
  6. foreach ($user in $users) {
  7.     # Check the primary email address
  8.     $primaryEmail = $user.PrimarySMTPAddress
  9.     $primaryResult = Get-MsIdHasMicrosoftAccount -Mail $primaryEmail
  10.     $results += [PSCustomObject]@{
  11.         UserEmail = $primaryEmail
  12.         HasPersonalMicrosoftAccount = $primaryResult
  13.     }
  14.     
  15.     # Check each alias
  16.     $aliases = $user.Aliases -split ","
  17.     foreach ($alias in $aliases) {
  18.         if ($alias -ne "-" -and ![string]::IsNullOrWhiteSpace($alias)) {
  19.             $aliasResult = Get-MsIdHasMicrosoftAccount -Mail $alias
  20.             $results += [PSCustomObject]@{
  21.                 UserEmail = $alias
  22.                 HasPersonalMicrosoftAccount = $aliasResult
  23.             }
  24.         }
  25.     }
  26. }# Export the results to a CSV file
  27. $results | Export-Csv -Path "personalMicrosoftAccountsCheck.csv" -NoTypeInformation -Encoding UTF8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement