Get UPN Suffix for all users in Office 365 (Powershell)

Get UPN Suffix for all users in Office 365 (Powershell);
# Connect Office 365
Connect-MsolService

# Get all users 
$users = get-msoluser -all

# Create array
$upnlist=@()

foreach ($i in $users)
   {
        $s = $i.UserPrincipalName.tostring()
        $upn  = $S.substring($s.IndexOf("@"))
        $upnlist+=$upn
   }

# Output
$upnlist | Group-Object

No comments: