list the email address of AD users in Powershell?

How to list the email address of AD users in Powershell?

Among the AD (Get-ADUser) attributes there is a « mail » attribute.

We will use:

For a specific user:
Get-ADUser $user -Properties mail | select mail

For multiple users (for example using a txt file):
$list_users = get-content « c:\temp\agent_list.txt »
foreach ($user in $list_users) {Get-ADUser $user -Properties mail | select mail}

For all AD users:
Get-ADUser -Filter * -Properties mail | select mail

For all users of a particular OU:
$OU= « OU=users, DC=FR »
Get-ADUser -SearchBase $OU -Filter * -Properties mail | select mail

a +

Laisser un commentaire