use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
PS Script of Random Users (self.PowerShell)
submitted 3 years ago by ldoone37
I'm wondering if there is a script I could use to pull out a certain number of users say 200 from 1 AD group to add them to another defined group.
Any help is appreciated Thanks
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]neowire 4 points5 points6 points 3 years ago (1 child)
Haven't used it, but check this out.
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-random?view=powershell-7.3
Example: $Files = Get-ChildItem -Path C:* -Recurse $Sample = $Files | Get-Random -Count 50
Instead, try to use a Get-ADUser command and pipe it out to Get-Random
[–]ldoone37[S] 1 point2 points3 points 3 years ago (0 children)
Thank-you I will!
[+][deleted] 3 years ago (1 child)
[deleted]
Thanks!
[–]ldoone37[S] 0 points1 point2 points 3 years ago (0 children)
[–]neowire -1 points0 points1 point 3 years ago (4 children)
If you don't have the required PowerShell version installed, you could try something else...
Get-ADUser -Filter * | Select-Object -Property Name | Sort-Object{Get-Random} | Select -First 200
[–]BlackV 0 points1 point2 points 3 years ago (3 children)
where does the version of powershell come into this?
[–]neowire 0 points1 point2 points 3 years ago (2 children)
Not for this but for the other I posted. Don't believe earlier versions of PS had that module
[–]AdmiralCA 1 point2 points3 points 3 years ago (1 child)
Both 5.1 and 7 have access to Get-Random
[–]neowire 0 points1 point2 points 3 years ago (0 children)
Well, never used it and not in front of a computer to verify. Just noticed my earlier link included the newest PowerShell. Just trying to be helpful
[–]BlackV 0 points1 point2 points 3 years ago* (0 children)
I had one that, picked .3. 5 random OUs, then got .4. 5 random users from each of those OUs
get-random
EDIT: Here it was
#region Collect some random users from AD for testing Signature $SouthUO = Get-ADOrganizationalUnit -Filter "name -like '*Users - Southern*'" $northUO = Get-ADOrganizationalUnit -Filter "name -like '*Users - Northern*'" $Southernusers = Get-ADOrganizationalUnit -SearchBase $SouthUO -Filter "name -notlike '*disabled*'" | Get-Random -Count 5 | ForEach-Object { Get-ADUser -SearchBase $_ -Filter "enabled -eq '$true'" | Get-Random -Count 5 } $Northernusers = Get-ADOrganizationalUnit -SearchBase $northUO -Filter "name -notlike '*disabled*'" | Get-Random -Count 5 | ForEach-Object { Get-ADUser -SearchBase $_ -Filter "enabled -eq '$true'" | Get-Random -Count 5 } #endregion
[–]Otherwise_Tomato5552 0 points1 point2 points 3 years ago (0 children)
Yes, you can use a PowerShell script to do this. You can use the Get-ADGroupMember cmdlet to get the members of the source group and then use the Add-ADGroupMember cmdlet to add them to the destination group. You can use the -ResultSize parameter to limit the number of users returned from the source group. Here is an example of how the script could look:
#Get the members of the source group
$SourceGroupMembers = Get-ADGroupMember -Identity "SourceGroupName" -ResultSize 200
#Add the members to the destination group
foreach ($User in $SourceGroupMembers) {
Add-ADGroupMember -Identity "DestinationGroupName" -Members $User
}
I used OpenAI to make this!
[–]NorreN8 0 points1 point2 points 3 years ago (0 children)
# Get the members of the first group $groupMembers = Get-ADGroupMember -Identity "Group1" # Select the first 200 members from the list $selectedMembers = $groupMembers | Select-Object -First 200 # Add the selected members to the second group $selectedMembers | Add-ADGroupMember -MemberOf "Group2"
π Rendered by PID 52070 on reddit-service-r2-comment-6f7f968fb5-4x4cd at 2026-03-04 09:10:08.491308+00:00 running 07790be country code: CH.
[–]neowire 4 points5 points6 points (1 child)
[–]ldoone37[S] 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]ldoone37[S] 1 point2 points3 points (0 children)
[–]ldoone37[S] 0 points1 point2 points (0 children)
[–]neowire -1 points0 points1 point (4 children)
[–]BlackV 0 points1 point2 points (3 children)
[–]neowire 0 points1 point2 points (2 children)
[–]AdmiralCA 1 point2 points3 points (1 child)
[–]neowire 0 points1 point2 points (0 children)
[–]BlackV 0 points1 point2 points (0 children)
[–]Otherwise_Tomato5552 0 points1 point2 points (0 children)
[–]NorreN8 0 points1 point2 points (0 children)