RT.
RT.

Reputation: 445

Select AD member properties + extra column

I'm getting AD members for a group and list certain properties from that group. I can't seem to get the group name using the following code:

Import-Module ActiveDirectory 
$strIdentity = "TestGroup"
$GroupMembers = Get-ADGroupMember -Identity $strIdentity -Recursive 
$GroupMembers | select $strIdentity, Name, ObjectClass | sort name | Format-Table

When I get the output, I get a {} instead of TestGroup.

Upvotes: 0

Views: 1055

Answers (2)

Shay Levy
Shay Levy

Reputation: 126932

Enclose $strIdentity in double quotes:

$GroupMembers | select "$strIdentity",Name, ObjectClass ...

If the above doesn't work, try using a calculated property:

$GroupMembers | select @{Name='GroupName';Expression={$strIdentity}},Name, ObjectClass ...

Upvotes: 1

Jeffery Hicks
Jeffery Hicks

Reputation: 943

Select-Object is for selecting properties of an object so selecting $strIdentity doesn't make any sense here. Omit that part from your Select statement.

But what I think you are trying to do is add a property to reflect the parent group name.

$groupmembers | select @{Name="Group";Expression={$strIdentity}}, Name, ObjectClass

Remember it is all about the objects not text.

Upvotes: 1

Related Questions