Hi
I am using Get-ADgroupMember piped into Get-ADuser to get a report. The Select portion gives me everything I need except the group name which I would like in the first column, is there any way to do that.
Here is my code:
$adGroupList = 'BI_FINANCE_F'
foreach ($group in $adGroupList)
{
$group
Get-ADGroupMember -identity $group -Recursive | Get-ADUser -Properties * | select displayname, name, employeeID, Department, title, physicalDeliveryOfficeName, Manager, sAMAccountName, givenName, surname, UserPrincipalName | Export-Csv -Append "C:\temp\GetADGroupMember3.csv" -NoTypeInformation -Encoding UTF8 ##| Select Name,ObjectClass,DisplayName
}
Thanks,
Derek
Welcome to the forums @Derekmb
Could you please format your code with the code tags </> here in the forum? The previous post can be updated. Thanks in advance.
To answer your question, you either need to generate a new object or use a calculated expression. Since most of the properties are coming from one cmdlet, a calculated expression is the easiest to implement:
$adGroupList = ‘BI_FINANCE_F’
$results = foreach ($group in $adGroupList) {
Get-ADGroupMember -identity $group -Recursive |
Get-ADUser -Properties * |
select @{Name='Group';Expression={$group}},
displayname,
name,
employeeID,
Department,
title,
physicalDeliveryOfficeName,
Manager,
sAMAccountName,
givenName,
surname,
UserPrincipalName
}
$results | Export-Csv -Append “C:\temp\GetADGroupMember3.csv” -NoTypeInformation -Encoding UTF8
1 Like
Hi Rob,
I went back to add the code tags and it seemed someone had already done it.
I’ll make sure to add them in the future.
Thanks again,
Derek