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.

Answers


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.


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 ...

Need Your Help

MS Access query to convert values from one currency to another currency

sql vba ms-access

Alright, I need a little assistance on a problem that I am facing.