Avatar of Scott Holmes
Scott Holmes
 asked on

Exporting AD User information from Distribution List

I'm trying to export out of my exchange server a list of users associated with a distribution list.  In the export I need to include AD information like the user EmployeeNumber.  I'm able to get the user list using the following commands

Get-DistributionGroup -identity "@all Corporate Employees" | get-distributiongroupmember | select-object @{label=”User”;expression={$_.DisplayName}},@{label=”Email Address”;expression={$_.PrimarySmtpAddress}},@{label=”Telephone Number”;expression={$_.phone}}, | Export-CSV C:\DistGroupData.csv

I need to pull AD information about the user so I can get the user EmployeeNumber.

Thank You
Scott Holmes
Exchange

Avatar of undefined
Last Comment
Saif Shaikh

8/22/2022 - Mon
Saif Shaikh

You may try below:

Import-Module activedirectory
$Users = GetDistributionGroupMember -Identity <groupname>
ForEach ($User in $Users) {
Get-ADUser -Identity $User.sAMAccountName -Properties Name, mail, EmployeeID, OfficePhone,l | select Name, mail, EmployeeID, OfficePhone,l
}
ASKER CERTIFIED SOLUTION
Saif Shaikh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Thomas U

Scott Holmes

ASKER
When I run Saif following command
 import-module activedirectory
$Members = get-adgroupmember "GROUP NAME" - recursive
$Members | get-aduser -properties * | select -property Name,EmailAddress,EmployeeNumber,TelephoneNumber,Office

I get the following errors.
Get-ADGroupMember : A positional parameter cannot be found that accepts argument '-'.
At line:2 char:12
+ $Members = get-adgroupmember "all Corprorate employees" - recursive
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ADGroupMember], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMember
 
Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null or an element of the argument collection contains a null value.
At line:3 char:12
+ $Members | get-aduser -properties * | select -property Name,EmailAddress,Employe ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
FOX

That is because there is a space between - recursive, try it again                   -recursive  (no space)
Saif Shaikh

You -recursive should be typed the way I did and fox is correct.
Scott Holmes

ASKER
Made the change and removed the space.  Ran the command again and received the following errors.
get-adgroupmember : Cannot find an object with identity: '@all Corprorate employees' under: 'DC=corp,DC=badcock,DC=org'.
At line:2 char:12
+ $Members = get-adgroupmember "@all Corprorate employees" -recursive
+            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (@all Corprorate employees:ADGroup) [Get-ADGroupMember], ADIdentityNotFoundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetAD
   GroupMember
 
Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null or an element of the argument collection contains a null value.
At line:3 char:12
+ $Members | get-aduser -properties * | select -property Name,EmailAddress,Employe ...
+            ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Saif Shaikh

Check the Sam account name in AD of the distribution group and use the same under identity parameter in the command.