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 - Local Admin Group

Reply
 
Old 10-31-2006   #1 (permalink)
XShell


 
 

Local Admin Group

I am trying to find out the members of local administrators group on my
machine.

$Admin=[adsi]"WinNT://./Administrators,Group"
$Admin.psbase.Invoke("Members")

but the Invoke("Members") method returns a COM object , which I am not sure
how to parse.

PS > $Admin.psbase.Invoke("Members").Gettype()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False __ComObject
System.MarshalByRefObject




My System SpecsSystem Spec
Old 11-01-2006   #2 (permalink)
Jeffery Hicks


 
 

Re: Local Admin Group

On Tue, 31 Oct 2006 09:17:06 -0800, XShell wrote:

> I am trying to find out the members of local administrators group on my
> machine.
>
> $Admin=[adsi]"WinNT://./Administrators,Group"
> $Admin.psbase.Invoke("Members")
>
> but the Invoke("Members") method returns a COM object , which I am not sure
> how to parse.
>
> PS > $Admin.psbase.Invoke("Members").Gettype()
>
> IsPublic IsSerial Name BaseType
> -------- -------- ---- --------
> True False __ComObject
> System.MarshalByRefObject


I think there is a shortcoming in the .NET classes that handle WinNT. You
would think you'd be on the right track. For example, using the LDAP
provider a script like this works just fine.

$Grp=[ADSI]"LDAP://CN=SAPIEN Authors,OU=SAPIEN,DC=MyCo,DC=local"

#create an array object from current group members
$grpMembers=@($grp.Member)

#display current group membership
Write-Host "There are currently" $grpMembers.Count "members in" $grp.Name
foreach ($user in $grpMembers) {$user}

I thought it would also work with the WinNT provider but I get the same
results. I can get some information about the group but not the members
either.

--
Jeffery Hicks - www.ScriptingAnswers.com
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
Scripting books: www.SAPIENPress.com <http://www.sapienpress.com/>
My System SpecsSystem Spec
Old 11-05-2006   #3 (permalink)
AlKos


 
 

Re: Local Admin Group

For WinNT provider use this script

$objRoot = [ADSI]"WinNT://./Administrators,group"
$objGrpMembers = @($objRoot.psbase.Invoke("Members"))
Write-Host "There are currently" $objGrpMembers.Count "members in"
$objRoot.Name
$objGrpMembers |Format-Table -HideTableHeader @{e={""};w=6},
@{e={$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_,
$null)};w=21}, @{e={$_.GetType().InvokeMember("Class", 'GetProperty', $null,
$_, $null)};w=8}, @{e={$_.GetType().InvokeMember("AdsPath", 'GetProperty',
$null, $_, $null)};w=50}

AlKos

"Jeffery Hicks" <"jhicks[at]SAPIEN.com" wrote:

> On Tue, 31 Oct 2006 09:17:06 -0800, XShell wrote:
>
> > I am trying to find out the members of local administrators group on my
> > machine.
> >
> > $Admin=[adsi]"WinNT://./Administrators,Group"
> > $Admin.psbase.Invoke("Members")
> >
> > but the Invoke("Members") method returns a COM object , which I am not sure
> > how to parse.
> >
> > PS > $Admin.psbase.Invoke("Members").Gettype()
> >
> > IsPublic IsSerial Name BaseType
> > -------- -------- ---- --------
> > True False __ComObject
> > System.MarshalByRefObject

>
> I think there is a shortcoming in the .NET classes that handle WinNT. You
> would think you'd be on the right track. For example, using the LDAP
> provider a script like this works just fine.
>
> $Grp=[ADSI]"LDAP://CN=SAPIEN Authors,OU=SAPIEN,DC=MyCo,DC=local"
>
> #create an array object from current group members
> $grpMembers=@($grp.Member)
>
> #display current group membership
> Write-Host "There are currently" $grpMembers.Count "members in" $grp.Name
> foreach ($user in $grpMembers) {$user}
>
> I thought it would also work with the WinNT provider but I get the same
> results. I can get some information about the group but not the members
> either.
>
> --
> Jeffery Hicks - www.ScriptingAnswers.com
> SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com
> Scripting books: www.SAPIENPress.com <http://www.sapienpress.com/>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
delete user from the local admin group PowerShell
Add local machine users to local admin group via GPO .NET General
Add domain admin to local admin group Vista General
In local Admin group but still Acess Denied. Vista account administration
local admin group members? 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