Untitled
unknown
plain_text
a year ago
903 B
25
Indexable
# Set path to the CSV file
$csvPath = "C:\temp\user.csv"
# Import the CSV file
$users = Import-Csv -Path $csvPath
# Group users by 'Functie'
$groupedUsers = $users | Group-Object -Property Functie
# Iterate over each group
foreach ($group in $groupedUsers) {
# Calculate 10% of users for the current function
$totalUsers = $group.Count
$percent10 = [math]::Ceiling($totalUsers * 0.1)
# Ensure at least 1 user is selected if there are users in the group
$numberToSelect = if ($percent10 -lt 1) { 1 } else { $percent10 }
# Select random 10% of users from the current function
$selectedUsers = $group.Group | Get-Random -Count $numberToSelect
# Update 'Retea_test' column for the selected users
foreach ($user in $selectedUsers) {
$user.Retea_test = "ok"
}
}
# Export the updated users back to CSV
$users | Export-Csv -Path $csvPath -NoTypeInformationEditor is loading...
Leave a Comment