In attempting to answer this question I came up against something that has bugged me for a while, and I have not been able to find an answer for.
The following script block will list the names of all members of the local administrators group.
$group = [ADSI]"WinNT://./Administrators"
@($group.Invoke("Members")) | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
However it will list only the names, and no other properties.
I'm fairly sure that there are other properties of Members
that I could extract but I don't understand how I would go about identifying what those other properties are.
I don't necessarily need to know the additional properties of that item, this is more a question of how I would go about finding them.
(I apologise if this is all a bit vague, I'm very much self taught at all of this and I'm well aware that I might be barking up the wrong tree and/or making regular horrible mistakes.)
Problem is that you are dealing with a COM Object, and these objects do not seem to provide a way to show you all in PowerShell.
You can also take a look at a similar question on a different (C#) thread here: https://stackoverflow.com/questions/10615019/get-property-names-via-reflection-of-an-com-object
Please see available properties here:
http://msdn.microsoft.com/en-us/library/aa705950(v=VS.85).aspx
and a similar example to your question:
http://social.technet.microsoft.com/Forums/windowsserver/en-US/b4d51781-e304-45b1-a7b1-c21b62263540/adsi-local-group-enum-from-fancy-powershell-to-simple-foreach-rewrite?forum=winserverpowershell
Since you are already getting a list of members names for the group, to get the details of the members I would just requery again, except against the individual user instead of the group.
Expanding on @Jacob's idea. When you enumerate the members of the group, only string objects are being returned, not AD user objects. Therefore, the only properties available are string properties (i.e. length, etc.). You need to query AD again using the name as the -identity parameter to retrieve the user properties.
In AD you could do something like this:
I can't speak for the code for WinNT