kevinrossen

Randomize-WinnersList

Aug 30th, 2020
2,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Get number of "spins" for randomizing
  2. $spins = Read-Host "How many spins for randomizer?"
  3.  
  4. ### Setup plain text file with comments for entry
  5. $rando = Get-Content $home\Desktop\rando\rando.txt
  6.  
  7. ### Clean up the text file removing extra lines
  8. $rando2 = $rando |
  9.     Select-String -Pattern ' Reply ' -NotMatch |
  10.     Select-String -Pattern 'badge icon' -NotMatch
  11. $rando2 | Set-Content $home\Desktop\rando\rando2.txt -Force
  12.  
  13. ### Create new text file only for people replying "In"
  14. $txtfile = "$home\Desktop\rando\rando3.txt"
  15. Set-Content -Path $txtfile -Value $null
  16. $content = $null
  17. $rando2 | ForEach-Object {
  18.     If(($_ -Like "In*" -Or $_ -Like "So In*" ) -And ($_ -NotLike "NOT in*") ) {
  19.         Add-Content -Path $txtfile -Value $content
  20.     }
  21.     $content = $_
  22. }
  23.  
  24. ### Check for duplicates
  25. $rando3 = Get-Content $home\Desktop\rando\rando3.txt
  26. $dupes = $rando3 | sort | Group-Object | Where-Object { $_.Count -gt 1 } | Select -ExpandProperty Name
  27. If ($dupes.Count -gt 0) {
  28.     Write-Host "Duplicate Entries Found. Please update rando3 file to continue."
  29.     Write-Host $dupes
  30.     Start-Sleep -Seconds 2
  31.     Write-Host -NoNewLine 'Press any key to continue...'
  32.     $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
  33. }
  34.  
  35. ### Randomize list
  36. $winners = $rando3 |
  37.     Sort-Object {Get-Random} |
  38.     Sort-Object {Get-Random} |
  39.     Sort-Object {Get-Random} |
  40.     Sort-Object {Get-Random} |
  41.     Sort-Object {Get-Random} |
  42.     Sort-Object {Get-Random} |
  43.     Sort-Object {Get-Random}
  44.  
  45. ### Generate Winners
  46. $runtime = Get-Date
  47. $win_path = "$home\Desktop\rando\winners.txt"
  48. New-Item -Path $win_path -Value "List randomized at $runtime`r`r" -Force
  49. Add-Content -Path $win_path -Value "Winners:"
  50. Add-Content -Path $win_path -Value $winners[0..6]
  51. Add-Content -Path $win_path -Value "`r`rBackups:"
  52. Add-Content -Path $win_path -Value $winners[7..10]
  53.  
  54. Get-Content $win_path
Advertisement
Add Comment
Please, Sign In to add comment