I have the following code to generate a list of members of the local administrators group on a machine:
param([string]$server)
$localGroupArray =@()
$groupName = 'Administrators'
$Group = [ADSI]"WinNT://$Server/$groupName,group"
$Members = @($Group.psbase.Invoke("Members"))
[Array]$class = $members | Foreach {$_.GetType().InvokeMember("Class", 'GetProperty', $null, $_, $null)}
[Array]$MemberNames = $Members | ForEach-Object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
This works as expected but I need to know more information about the object such as domain if it is a domain group. So I would like to list all of properties that I can query using InvokeMember but I been unable to find a good solution.
Normal ways such as using Get-Member do not work since this is a system._comobject. The following is the output of Get_member on the Comobject:
Name MemberType Definition
---- ---------- ----------
CreateObjRef Method System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType)
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetLifetimeService Method System.Object GetLifetimeService()
GetType Method type GetType()
InitializeLifetimeService Method System.ObjectInitializeLifetimeService()
ToString Method string ToString()
I have also tried seeing if I could find a c# solution and was able to find this link: How return the type of a System.__COMObject in System.Type in C#
However, the program I wrote did not get any PropertyDescription when I try to run GetProperties on the comobect. I can also post the c# code if needed but I felt it was a little off topic since I am posting only with the Powershell tag.