Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get initial 200users from AD group membership using PowerShell script

I have a AD group "xyz" having 1500 members in it. I want to select initial 200 users and send emails to them.

I am not sure how to filter the 200 users from the group using PowerShell code,i have all members list but want to know how can I filter 200 users from it?

please help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can abort a pipeline after receiving X input objects with Select-Object -First X:

Get-ADGroupMember xyz |Select-Object -First 200

If you want a random sample, use Get-Random -Count:

Get-ADGroupMember xyz |Get-Random -Count 200

Beware that Active Directory doesn’t guarantee any specific sort order, so you’ll have to manually keep track of which users you’ve already processed (if you want to only process each member once for example)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading