Link to home
Start Free TrialLog in
Avatar of Indyrb
IndyrbFlag 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.

Thanks
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, as a good start, try the VBScript here:
https://www.experts-exchange.com/questions/27042055/AD-Group-Membership-Outputs-and-Account-Status-via-e-mail.html?anchorAnswerId=35829520#a35829520

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

Regards,

Rob.
Avatar of Indyrb

ASKER

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

ASKER

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.
Avatar of Indyrb

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Indyrb

ASKER

You are right the (mobile) is a contact.
How can I add both contanct and users to the group membership report?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Indyrb

ASKER

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
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

Rob.