Forum Discussion

mfranhind115's avatar
mfranhind115
Brass Contributor
Sep 13, 2022

powershell and MSonline: how to get all the aliases in my accounts list

Hi all, under my tenant I have several domains with their accounts.   I would like to write a script (or a single command even), to get all the aliases.   Something like this would be fine:   ...
  • Harm_Veenstra's avatar
    Sep 13, 2022

    mfranhind115 

     

    This should give you a list of Alias and UPN, use connect-msolService first

    $total = @()
    foreach ($user in Get-MsolUser -All) {
        foreach ($alias in $user.ProxyAddresses) {
            $founduser = [pscustomobject]@{
                Alias = $alias.Split(':')[1]
                UPN   = $user.UserPrincipalName
            }
            $total += $founduser
        }
    }
    
    $total | Sort-Object Alias

Resources