Avatar of Indyrb
Flag for United States of America asked on

query group membership

I am in need of a powershell or vbscript that does the following

query exchange\active directory for specified security
distrubtion groups.
list the members of each specified group
export into a pretty report
email report\attachment to specified user.
Schedule script to run monthly.

There are about 30 - 40 groups I need to know the membership of.
I already have the group names \ emails
I dont want to list all groups in ADS as that would be way to many, just the ones that
I have listed.
I dont want 30-40 scripts for each group, I want 1 script that queries the specified groups and exports membership to report, then email. I want to schedule this script to run monthly and send to specified user, so they can evaluate group membership.

I appreciate any help and assistance with creating the script.

VB ScriptPowershellActive Directory

Avatar of undefined
Last Comment

8/22/2022 - Mon

Hi, as a good start, try the VBScript here:

it reads the groups from the array at the top, instead of a text file, but that can be changed if you want.



How would you go about reading from a text file? What if the groups are in different OUs inside Active Directory?

Okay, I just entered in the groups into the script and away it goes.
I want to create a scheduled task that automates this on the first day of each month.
I remmed out the wscript.excho "Done"
created a task a pointed to the vbs. used the elevated permissions
But it wont work,
It will work if i use it interactively but not via scheduled task.
also I tried creating a batch script and used cscript nameofvbsfile.vbs and that failed too.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

One more thing in addition to the above...

If there is a user name Adam Jones and also a user account named Adam Jones (mobile)
in the ABC group

It only list Adam jones,  not both user accounts. how can we fix this?

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

You are right the (mobile) is a contact.
How can I add both contanct and users to the group membership report?
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Thanks so much... Still having issues running this as a scheduled task. Even put in my credentials.
If i run it interactly it works just fine, if I run via the taskscheduler it doesnt work
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Is the admingroupreport.csv created, or not at all?  Delete it, then run the scheduled task, and see.  It will definately need to run as an account that has access to the AD, and you should run it with highest privileges as well.

If you can see that it's creating the report file, does it write any data to it?  If it's not creating the report file, try setting the report file to a location where everyone has full rights, and you may as well put the script there to execute it from as well.

Also, as the scheduled task, run
cscript C:\Scripts\YourScript.vbs