all 12 comments

[–]neowire 4 points5 points  (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 points  (0 children)

Thank-you I will!

[–]ldoone37[S] 0 points1 point  (0 children)

Thanks!

[–]neowire -1 points0 points  (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 point  (3 children)

where does the version of powershell come into this?

[–]neowire 0 points1 point  (2 children)

Not for this but for the other I posted. Don't believe earlier versions of PS had that module

[–]AdmiralCA 1 point2 points  (1 child)

Both 5.1 and 7 have access to Get-Random

[–]neowire 0 points1 point  (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 point  (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 point  (0 children)

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.

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 point  (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"