![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Question when using System.DirectoryServices.DirectoryEntry Greetings! I'm trying to list the users that are part of a machine's local Administrator group. Here is the syntax that I am using: (assuming computer name = TEST and local administrator password = pass) $base = New-Object -typeName System.DirectoryServices.DirectoryEntry("WinNT://TEST", "TEST \Administrator", "pass") $group = $base.PSBase.Children.Find("Administrators") $members = $group.PSBase.Invoke("Members") $members | % { $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) I'm trying to use the local Administrator on the computer because I cannot guarantee that any other user has been added to the local Administrator group. All of these machines are on a domain and the local Administrators group could have domain users in it. It appears that by using this syntax, I am not getting the full list of users in the Administrators group. Does anyone have any advice? Thanks, Kyjan |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Question when using System.DirectoryServices.DirectoryEntry This works for me $Group = [ADSI]"WinNT://$computer/Administrators,Group" $members = $group.PSBase.Invoke("Members") $members | % { $_.GetType().InvokeMember("Name", 'GetProperty', $null,$_, $null) } <HolySaphAngel@xxxxxx> wrote in message news:0a031d88-704c-47d6-89c7-e95cc0597612@xxxxxx Quote: > Greetings! > > I'm trying to list the users that are part of a machine's local > Administrator group. Here is the syntax that I am using: > > (assuming computer name = TEST and local administrator password = > pass) > > $base = New-Object -typeName > System.DirectoryServices.DirectoryEntry("WinNT://TEST", "TEST > \Administrator", "pass") > $group = $base.PSBase.Children.Find("Administrators") > $members = $group.PSBase.Invoke("Members") > $members | % { $_.GetType().InvokeMember("Name", 'GetProperty', $null, > $_, $null) > > I'm trying to use the local Administrator on the computer because I > cannot guarantee that any other user has been added to the local > Administrator group. All of these machines are on a domain and the > local Administrators group could have domain users in it. It appears > that by using this syntax, I am not getting the full list of users in > the Administrators group. > > Does anyone have any advice? > > Thanks, > > Kyjan |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Question when using System.DirectoryServices.DirectoryEntry This is very interesting. Please review the output below: PS C:\Temp> $myBase = [ADSI] "WinNT://TEST" PS C:\Temp> $myBase.PSBase.Children.Find("Administrators") | % {$_.PSBase.Invoke("Members")} | % {$_.GetType()} IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False __ComObject System.MarshalByRefObject True False __ComObject System.MarshalByRefObject True False __ComObject System.MarshalByRefObject PS C:\Temp> $myBaseBad = New-Object -typeName System.DirectoryServices.DirectoryEntry("WinNT://TEST", "TEST \Administrator", "pass") PS C:\Temp> $myBaseBad.PSBase.Children.Find("Administrators") | % {$_.PSBase.Invoke("Members")} | % {$_.GetType()} IsPublic IsSerial Name BaseType -------- -------- ---- -------- True False __ComObject System.MarshalByRefObject I would fully expect both commands to give the same results - 3 children, which is the number of objects (1 user and 2 groups) in the Administrator group. Am I doing something wrong that prevents $myBaseBad from showing the same members as $myBase? Kyjan On Jul 17, 9:59*pm, "Brandon [MVP]" <tshell.m...@xxxxxx> wrote: Quote: > This works for me > > $Group = [ADSI]"WinNT://$computer/Administrators,Group" > $members = $group.PSBase.Invoke("Members") > $members | % { $_.GetType().InvokeMember("Name", 'GetProperty', $null,$_, > $null) } > > <HolySaphAn...@xxxxxx> wrote in message > > news:0a031d88-704c-47d6-89c7-e95cc0597612@xxxxxx > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| using .Net DirectoryEntry to enumerate domains | Vista networking & sharing | |||
| System.DirectoryServices.Protocols | PowerShell | |||
| System.DirectoryServices.DirectoryEntry & the accountExpires property | PowerShell | |||
| System.Directoryservices.Protocols | PowerShell | |||
| Re: PSH: DirectoryEntry doesn't have Path Property??? | PowerShell | |||