Hello!

I need a script, that will list me all user and groups, that he belongs to.
But in special way:

user1
group1
group2
group3
user2
group1
group2
etc

I have this script, but i don't know how to change it.... :(

Set colGroups = GetObject("WinNT://.")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
For Each objUser in objGroup.Members
If objUser.name = "test" Then
Wscript.Echo objGroup.Name
End If
Next
Next

Anyone help me?

Re: Local groups that user belongs to by Alexander

Alexander
Wed Aug 09 07:54:55 CDT 2006

Please, have a look:

strComputer = "."
Set colGroups = GetObject("WinNT://" & strComputer & "")
Set colUsers = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
colUsers.Filter = Array("user")
For Each objUser In colUsers
Wscript.Echo objUser.Name
For Each objGroup In colGroups
For Each objMember In objGroup.Members
If objMember.Name = objuser.name Then
WScript.Echo vbTab & objGroup.Name
End If
Next
Next
Next

Does it fit you???

--

Regards,
Alexander Trofimov

"Leszek" <marek@zegarek.com> wrote in message
news:e3Jr3r6uGHA.3392@TK2MSFTNGP04.phx.gbl...
> Hello!
>
> I need a script, that will list me all user and groups, that he belongs
> to.
> But in special way:
>
> user1
> group1
> group2
> group3
> user2
> group1
> group2
> etc
>
> I have this script, but i don't know how to change it.... :(
>
> Set colGroups = GetObject("WinNT://.")
> colGroups.Filter = Array("group")
> For Each objGroup In colGroups
> For Each objUser in objGroup.Members
> If objUser.name = "test" Then
> Wscript.Echo objGroup.Name
> End If
> Next
> Next
>
> Anyone help me?
>



Re: Local groups that user belongs to by Leszek

Leszek
Wed Aug 09 08:24:44 CDT 2006

Thanks!
That's it! :)

U¿ytkownik "Alexander Trofimov" <a_trofimov@front.ru> napisa³ w wiadomo¶ci
news:OB748J7uGHA.1436@TK2MSFTNGP02.phx.gbl...
> Please, have a look:
>
> strComputer = "."
> Set colGroups = GetObject("WinNT://" & strComputer & "")
> Set colUsers = GetObject("WinNT://" & strComputer & "")
> colGroups.Filter = Array("group")
> colUsers.Filter = Array("user")
> For Each objUser In colUsers
> Wscript.Echo objUser.Name
> For Each objGroup In colGroups
> For Each objMember In objGroup.Members
> If objMember.Name = objuser.name Then
> WScript.Echo vbTab & objGroup.Name
> End If
> Next
> Next
> Next
>
> Does it fit you???
>
> --
>
> Regards,
> Alexander Trofimov
>
> "Leszek" <marek@zegarek.com> wrote in message
> news:e3Jr3r6uGHA.3392@TK2MSFTNGP04.phx.gbl...
>> Hello!
>>
>> I need a script, that will list me all user and groups, that he belongs
>> to.
>> But in special way:
>>
>> user1
>> group1
>> group2
>> group3
>> user2
>> group1
>> group2
>> etc
>>
>> I have this script, but i don't know how to change it.... :(
>>
>> Set colGroups = GetObject("WinNT://.")
>> colGroups.Filter = Array("group")
>> For Each objGroup In colGroups
>> For Each objUser in objGroup.Members
>> If objUser.name = "test" Then
>> Wscript.Echo objGroup.Name
>> End If
>> Next
>> Next
>>
>> Anyone help me?
>>
>
>



Re: Local groups that user belongs to by Arvind-ACS

Arvind-ACS
Wed Aug 09 10:16:13 CDT 2006

Hi,
You can create a text or XLS file, using the following command
Set objFile = objFSO.CreateTextFile("C:\Grpmem.txt")

and then use the objfile.writeline property to write the values out if
you are creating a text file. If you want the report in an excel format
then you have to tweak with the cells.

here's what you can do.

Set objExcel = CreateObject("Excel.Application")

'Open the worksheet
objExcel.Workbooks.Open "C:\grpmem.xls"
i=1
j=1
cn = "<User Name>"
Set colGroups = GetObject("WinNT://.")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
For Each objUser in objGroup.Members
objExcel.Cells(i,j) = "Test" 'or you can change this with
objUser.Name to automaticaly write the user name in sheet.
If objUser.name = "test" Then
i=i+1
objExcel.Cells(i,j) = objGroup.Name

End If
Next
j=j+1
i=1
Next

objExcel.Workbooks.Close
Set objExcel = nothing


Let me know if it works for you.

Leszek wrote:

> Hello!
>
> I need a script, that will list me all user and groups, that he belongs to.
> But in special way:
>
> user1
> group1
> group2
> group3
> user2
> group1
> group2
> etc
>
> I have this script, but i don't know how to change it.... :(
>
> Set colGroups = GetObject("WinNT://.")
> colGroups.Filter = Array("group")
> For Each objGroup In colGroups
> For Each objUser in objGroup.Members
> If objUser.name = "test" Then
> Wscript.Echo objGroup.Name
> End If
> Next
> Next
>
> Anyone help me?