combining get-adgroupmember and get-aduser info into a single report

would there be an easy way to merge the output of get-adgroupmember with some of the attributes of get-aduser? I basically need to verify a number of group members but being able to write them out to a csv type report and also pull in a number of get-aduser attributes, e.g. enabled, accountexpirydate etc would really help with this exercise.

What I am suggesting is I want to specify get-adgroupmember group, and the output be written to CSV in a table format, which of course will show all group members, but then also include some attributes about the aduser, namely attributes: enabled, email address, accountexpirydate, lastlogintimestamp. By default get-adgroupmember only returns these attributes per group member which isn't quite enough:

  • distinguisedname
  • name
  • objectclass
  • objectGUID
  • SamAccountName
  • SID

Not sure if there's anyway to amend the output of cmdlet get-adgroupmember itself to show other user attributes to avoid having to merge the output of 2 commands. I suppose I could run 2 commands and join them into something like access, but an all in one way in PowerShell would be ideal to save time.
LVL 4
pma111Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin StanushApplication DeveloperCommented:
I'm sure there is a way to do this in Powershell, but a few years back we implemented this into Hyena, which you can get for a free 30-day trial.  If you need this information now (right now), it takes only seconds to install.  Then, you can select any group (or selection of groups), right click, select View Group Members > View Direct Members Only.  The resulting view will have both group and member attributes but is completely customizable, so you can add any additional user (or group) attributes that you want.  Since Hyena is a GUI, you can also select which groups you want to do this on, as due to how AD works, this is an intense procedure.
Derek SouterITO Svc Delivery Cons IIICommented:
get-adgroupmember "techadmin" -recursive | % {
	$group=$_
	get-aduser $_ -Properties Employeeid | select @{n="Group";e={$group}},Name,SurName,GivenName,Employeeid 
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
footechCommented:
Derek's method is the way to go if you need to show any properties that aren't possible to output from Get-ADUser.  It makes use of a calculated property to add the group (actually an adjustment would be needed so that just the group name is added).

If only properties output from Get-ADUser are needed, then something like this would work.
Get-ADGroupMember "domain admins" -Recursive |
 Get-ADUser -Properties enabled, mail, accountexpires, lastlogontimestamp |
 Select samaccountname,enabled, mail, accountexpires, lastlogontimestamp

Open in new window

You need to specify with additional properties beyond the default set you want retrieved by Get-ADUser, and then in the Select-Object command you specify all properties that you want to show (this is optional if you don't want to exclude any output from the Get-ADUser command.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.