Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Question when using System.DirectoryServices.DirectoryEntry

Reply
 
Old 07-17-2008   #1 (permalink)
HolySaphAngel


 
 

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 SpecsSystem Spec
Old 07-17-2008   #2 (permalink)
Brandon [MVP]


 
 

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 SpecsSystem Spec
Old 07-21-2008   #3 (permalink)
Kyjan


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46