SOLVED

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

Brass Contributor

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:

 

alias, UPN

...

 

obviously, if a UPN has multiple aliases, the list should show multiple lines....

 

thanks!

mf

3 Replies
best response confirmed by mfranhind115 (Brass Contributor)
Solution

@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
excellent Harm_Veenstra!

just the last request: any chance to exclude the alias if identical to UPN?

thank you!

@mfranhind115  No problem, I think this should work:

 

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

$total | Sort-Object Alias
1 best response

Accepted Solutions
best response confirmed by mfranhind115 (Brass Contributor)
Solution

@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

View solution in original post