简体   繁体   中英

Export Email Address and Mobile Number from Office 365 Distribution Group

I can't seem to find a way to export an email address and a phone number from a specific DG.

Hey guys,

I'm trying to get an email and a phone number from each member in a DG. I can't get the phone number.

I used any words I could think of

Get-DistributionGroupMember -Identity $DG -ResultSize Unlimited | Select PrimarySMTPAddress, Mobile, MobilePhone,
Phone, PhoneNumber, MobileNumber

I also tried

Get-MsolGroupMember -GroupObjectId | select DisplayName, MobileNumber

Nothing yields results. If I try the same comment with a simple Get-MsolUser it WILL work. Why?

It's this field in the Exchange admin:

在此处输入图片说明

Any ideas?

Thanks :)

AFAIK the Exchange cmdlet Get-DistributionGroupMember returns an array of ReducedRecipient member objects where not all AD user properties are stored.
In order to get the user properties you need, you will also have to use either the Get-ADUser or the Get-MsolUser cmdlet.

The code below uses Get-ADUser (untested)

$result = Get-DistributionGroupMember -Identity $DG -ResultSize Unlimited | 
    Where-Object { $_.RecipientType -eq 'UserMailbox' } | 
    ForEach-Object {
        $user = Get-ADUser -Identity $_.SamAcountName -Properties MobilePhone, HomePhone, OfficePhone
        [PsCustomObject]@{
            'DistributionGroup'  = $DG
            'DisplayName'        = $_.DisplayName
            'PrimarySmtpAddress' = $_.PrimarySmtpAddress
            'MobilePhone'        = $user.MobilePhone
            'HomePhone'          = $user.HomePhone
            'OfficePhone'        = $user.OfficePhone
            'City'               = $_.City
            'Country'            = $_.CountryOrRegion
        }
    }

# output on screen
$result

# output to CSV
$result | Export-Csv -Path ('D:\DistributionGroupMembers_{0}.csv' -f $DG) -NoTypeInformation -Encoding UTF8

In order to use the Get-ADUser cmdlet you need to Import-Module ActiveDirectory .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM