Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 11, 2011 9:50 PM
Hi,
Using the command: $a = Get-QADGroupMember $Group | select LogonName | Out-File "c:\temp\menu.txt"
I can get the logon names of the members of an AD group.
And using the command: $a = Get-QADUser -LogonName $item | select mail
$a.mail
I can get the EMail address of an AD User.
How do I take the out put of the first command and use that as an input for the second command so that I get a List of the Group members EMail addresse?
I tried this:
$TextFile = gc "c:\temp\menu.txt" | Sort-Object
foreach ($item in $TextFile) {
Write-Host $item
$a = Get-QADUser -LogonName $item | select mail }
But it does not like $item as a parameter.
Get-QADUser : The search filter is invalid.
At C:\Scripts\PS1\Get-GroupMembers.ps1:35 char:18
+ $a = Get-QADUser <<<< -LogonName $item
TIA
OldDog
All replies (11)
Tuesday, January 11, 2011 10:19 PM ✅Answered | 1 vote
output the logonnames for $Group
Get-QADGroupMember $Group | select LogonName | %{Get-QADUser -LogonName $_.logonName}
and pipe them to a foreach where you get the users from
whole command should look like this
Get-QADGroupMember $Group | select LogonName | %{Get-QADUser -LogonName $_.logonName} | select mail | %{$_.mail}
Tuesday, January 11, 2011 10:33 PM ✅Answered | 3 votes
this is how it works with the ms-ad-cmdlets
import-module activedirectory
Get-ADGroupMember "Domain Users" | select samaccountname | %{Get-ADUser $_.samaccountname -Properties mail} | %{write-output "$($_.samaccountname) `t`t $($_.mail)"}
Wednesday, January 12, 2011 5:54 PM ✅Answered
Thanks,
Here is my script that works:
param( [string] $Group)
Write-Host "Group Name: " $Group
Add-PSSnapin Quest.Activeroles.ADManagement -EA silentlycontinue
Get-QADGroupMember $Group |
select DisplayName |
Sort-Object $_.DisplayName |
%{Get-QADUser -DisplayName $_.DisplayName} |
select Name,mail |
%{$_.Name + " " + $_.mail}|
Out-File "c:\temp\mail.txt"
Wednesday, January 12, 2011 3:45 PM
Thanks, that seems to work. However, there are some blanks in the LogonNames and the script hangs when it hits a blank.
How would I get it to skip the blanks or eliminate them?
TIA OldDog
Wednesday, January 12, 2011 3:47 PM
Correct me if I am wrong, but dosen't this require at least one AD Controller be Windows 2008?
We are not the advanced here.
OldDog
Wednesday, January 12, 2011 4:45 PM
i use win2008r2, win 2003 doesn´t have the activedirectory module
Wednesday, January 12, 2011 4:50 PM
Thanks, that seems to work. However, there are some blanks in the LogonNames and the script hangs when it hits a blank.
How would I get it to skip the blanks or eliminate them?
TIA OldDog
did you try the samaccountname?
can you show an example, and which command did you run
Monday, May 5, 2014 7:19 PM
I'm not sure why everyone is making this so complicated....I used this in Powershell using ActiveRoles Management Shell from Quest.
http://www.quest.com/powershell/activeroles-server.aspx
Get-QADUser -MemberOf "Group Name Goes Here" | select firstname, lastname, email, logonname >> test.txt
This gave me a text file I can import into excel with the First Name, Last Name, Email address and Username.
Monday, May 5, 2014 7:34 PM
I'm not sure why everyone is making this so complicated....I used this in Powershell using ActiveRoles Management Shell from Quest.
http://www.quest.com/powershell/activeroles-server.aspx
Get-QADUser -MemberOf "Group Name Goes Here" | select firstname, lastname, email, logonname >> test.txt
This gave me a text file I can import into excel with the First Name, Last Name, Email address and Username.
You should use | Export-Csv instead of >> if you want to open the file in Excel.
There's almost no reason to use the Quest tools any longer anyway.
Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)
Thursday, January 19, 2017 7:55 PM
Hello
what if you needed to only get email for specific group of users?
Thanks
Friday, January 20, 2017 5:42 AM
Get-ADGroupMember -Identity "ABC" | where {$_.objectclass -like "User"} | foreach {get-aduser -Identity $_.distinguishedname -Properties * | select Name,Emailaddress}