Global Group User list
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Global Group User list

 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming
Author Message
Zeno
Guest





Posted: Tue Jan 04, 2005 2:35 pm    Post subject: Global Group User list Reply with quote

Hi ..................


I'm new to scripting.......and I'm trying to figure out how I can get a
listing of all the Global groups and users in the Global Groups in our
domain........

Any help appreciated.........


Zeno
Back to top
SubnetJO
Guest





Posted: Tue Jan 04, 2005 8:35 pm    Post subject: RE: Global Group User list Reply with quote

Try the following code.
The code below shows, in tabular output in the shell window, all domain
groups, listing all users belonging to each one.
For each user the script shows:
- ID (progressive count)
- Username
- Full name
- Description
- If the user is active

REQUIREMENTS:
- you have to be logged as a domain user on a domain joined computer
- Set the "strcomputer" variable with your domain name (now set with
"MyDomain" string)

For each group the script shows the group name and the number of users that
belong to it.

The script cannot be ran with "wscript", of course.
It preserves from running it with "wscript", showing an help message box.
Run it from command-line.
Write:

cscript /nologo DomainUsers.vbs -?

to get sintax informations.

If you use the "-g" switch at the command-line, you have the option to swoh
the information about only one group (not about all domain groups).

[script starts here]
[copy and paste the ode below in a text file and name it "DomainUsers.vbs"]

'*****************
'* CSCRIPT CHECK *
'*****************
If Instr(1,wscript.fullname,"wscript",1)>0 then
msgbox vbcrlf & "Execute this script with ""CSCRIPT""." & vbcrlf & vbcrlf &
vbcrlf & "Digit at the command-line:" & vbcrlf & vbcrlf& " cscript /nologo
domainusers.vbs -?" & vbcrlf & vbcrlf & "to get informations about the
sintax." & vbcrlf, +vbinformation,"DomainUsers"
wscript.quit
end if

DIM GroupToCheck
DIM enviroment
Enviroment="AllDomainGroups"


'************************
'* Command-line parsing *
'************************
if wscript.arguments.count > 0 then
if wscript.arguments.Item(0)="-?" then
ShowHelp
wscript.quit
end if
end if

for i=0 to wscript.arguments.count - 1
if lcase(wscript.arguments.Item(i))="-g" then
Enviroment="OneGroupOnly"
GroupToCheck=wscript.arguments.Item(i+1)
end if
next


'**********************
'* Script Enviroments *
'**********************
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objExecObject= WSHShell.Exec("mode.com con cols=110 lines=50")

'This 1/10 of second sleep, is needed to let the shell window to
'get the new dimensions before the script execution
wscript.sleep 100


'*****************
'* Script "Core" *
'*****************
strComputer = "MyDomain"
Set colgroups = GetObject("WinNT://" & strcomputer & "")
colgroups.Filter = Array("group")
Select case enviroment
case "AllDomainGroups"
For Each objGroup In colgroups
UserID=1
HeaderPrint(objgroup.name)
For Each objUser in objGroup.Members
UserLinePrint
UserID,objuser.name,objuser.fullname,objuser.description,objuser.accountdisabled
UserID=UserID+1
Next
wscript.stdout.writeblanklines 1
wscript.stdout.writeLine " Number of users in " & objgroup.name &
" group: " & userid -1
next
case "OneGroupOnly"
For Each objGroup In colgroups
IF objGroup.name = GroupToCheck THEN
UserID=1
HeaderPrint(objgroup.name)
For Each objUser in objGroup.Members
UserLinePrint
UserID,objuser.name,objuser.fullname,objuser.description,objuser.accountdisabled
UserID=UserID+1
Next
wscript.stdout.writeblanklines 1
wscript.stdout.writeLine " Number of users in " &
objgroup.name & " group: " & userid -1
end if
next
end select


'****************************************************
'* Routine to print users "lines" in tabular format *
'****************************************************
Sub UserLinePrint(UserID,username,fullname,description,disabled)
padID= 4 - Len(UserID)

If Len(username) < 20 then
padnomeutente= 20 - Len(username)
else
padnomeutente = 0
end if

if Len(fullname) < 35 then
padfullname = 35 - Len(fullname)
else
padfullname=0
end if

if Len(description) < 35 then
paddescription = 35 - Len(description)
else
paddescription=0
end if

if lcase(disabled)="false" then
active="YES"
else
active="NO"
end if

writeline = " " & UserID & Space(padID) & " " & left(username,20) &
Space(padnomeutente) & " " & Left(fullname,35) & space(padfullname) & " " &
Left(description,35) & space(paddescription) & " " & active
wscript.echo writeline
end sub


'***************************************************
'* Routine to print the "header" of tabular output *
'***************************************************
Sub HeaderPrint(GroupName)
wscript.stdout.writeblanklines 3
wscript.stdout.writeline " Global Group Name: " & GroupName
wscript.stdout.writeblanklines 1
wscript.stdout.writeline " ID Username FullName
Description Active"
wscript.stdout.writeline " ---- --------------------
----------------------------------- ----------------------------------
------"
end sub


'**************************************
'* Routine to show the "help message" *
'**************************************
sub ShowHelp
wscript.stdout.writeblanklines 2
wscript.stdout.writeline "Shows all users belonging to each domain global
group, or belonging"
wscript.stdout.writeline "to a specific domain global group"
wscript.stdout.writeblanklines 1
wscript.stdout.writeline " SINTAX:"
wscript.stdout.writeblanklines 1
wscript.stdout.writeline " domainusers.vbs [-?] [-g GrOuPnAmE]"
wscript.stdout.writeblanklines 1
wscript.stdout.writeline " -? Shows this help."
wscript.stdout.writeline " Must be the first parameter.
All other parameters will take no effect."
wscript.stdout.writeline " -g GrOuPnAmE Switch to show only the
users belonging to the group named ""GrOuPnAmE""."
wscript.stdout.writeline " The name of the domain
global group may be CaSe SeNsITiVe."
wscript.stdout.writeblanklines 1
wscript.stdout.writeline " Without switches, the command shows all
informations for all groups in the domain."
wscript.stdout.writeblanklines 1
end sub

[end of script]

Sorry if the server message formatting breaks the lines.
I choosed to post the code here to make it available for all.
If you want, provibe me an email address, I'll sent the script as
attachment, reneming the file "DomainUsers.txt", to avoid mailserver security
check.

IMPORTANT!
The code above is provided "as is".
No warranty is provided by the writer.
Use it at your own risk.

Of course, feel free to modify the script for your needs.
Sorry, if you find errors in the output.
This script is a "portion" of a larger script I wrote... localized in
italian language!
Rewriting this portion of the script to work "stand alone", I tried to
translate it into english (output, variable, routines).

The script is widely tested in my enviroment:
- NT4 Domain
- WinXPpro SP2 domain client


Hope have been helpful.

SubnetJO
Italy
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB