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
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
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
Import-Module activedirectory
$Users = GetDistributionGroupMember
ForEach ($User in $Users) {
Get-ADUser -Identity $User.sAMAccountName -Properties Name, mail, EmployeeID, OfficePhone,l | select Name, mail, EmployeeID, OfficePhone,l
}