Untitled
unknown
plain_text
a year ago
1.3 kB
6
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 8% of users for the current function $totalUsers = $group.Count $percent8 = [math]::Ceiling($totalUsers * 0.08) # Get the users already marked as "ok" $existingOkUsers = $group.Group | Where-Object { $_.Retea_test -eq "ok" } $existingOkCount = $existingOkUsers.Count # Calculate the number of additional users needed to reach 8% $numberToSelect = $percent8 - $existingOkCount # Ensure the number of additional users to select is at least 0 if ($numberToSelect -gt 0) { # Select random users from the remaining users in the current function $remainingUsers = $group.Group | Where-Object { $_.Retea_test -ne "ok" } $selectedUsers = $remainingUsers | 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 -NoTypeInformation
Editor is loading...
Leave a Comment