Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. $ApiKey = "rtKJRZHxQYYE4Um8Y-ty"
  2. $GitLabUrl = "https://gitlab.dev.onsolve.com"
  3. $Header = @{ "Private-Token"=$ApiKey }
  4. [int] $retentionPolicy = (-45)
  5.  
  6.  
  7. # GET request function
  8. function Get-GitLabResource([string]$Uri) {
  9. Write-Host "[GET]: $GitLabUrl/$Uri"
  10. return Invoke-RestMethod -Method Get -Uri "$GitLabUrl/$Uri" -Header $Header
  11. }
  12.  
  13. function calcBlockUsers (){
  14. param(
  15. [int] $retentionPolicy,
  16. $userList
  17. )
  18. $userList | Where-Object
  19. }
  20.  
  21. # POST request function
  22. function Post-GitLabResource([string]$Uri, [object]$resource) {
  23. Write-Host "[POST]: $GitLabUrl/$Uri"
  24. Invoke-RestMethod -Method Post -Uri "$GitLabUrl/$Uri" -Body $($resource | ConvertTo-Json -Depth 10) -Header $Header
  25. }
  26.  
  27. function changeMonth() {
  28. param{
  29. $badDate
  30. }
  31. $hardDate = "2019-09-17T08:16:54.940-04:00"
  32. $monthStr = $hardDate.Substring(5, 2)
  33. $monthInt = [int]$monthStr
  34. $monthInt = ($monthInt - 1)
  35. $monthStr = [String]$monthInt
  36. if($monthStr.length -lt 2){
  37. $monthStr.Insert(0,"0")
  38. }
  39. Write-Host $monthStr
  40.  
  41. $formattedDate = (($hardDate.Substring(0, 5)) + ($monthStr) + ($hardDate.substring(7)))
  42. Write-Host $formattedDate
  43.  
  44. return $formattedDate
  45. }
  46.  
  47. try{
  48. $userList1 = Get-GitLabResource "api/v4/users?per_page=100&page=1&active=true"
  49. $userList2 = Get-GitLabResource "api/v4/users?per_page=100&page=2&active=true"
  50. $userList3 = Get-GitLabResource "api/v4/users?per_page=100&page=3&active=true"
  51. $userList = $userList1 + $userList2 + $userList3
  52.  
  53. $hardDate = "2019-07-17T08:16:54.940-04:00"
  54.  
  55. $date = Get-Date -Format o
  56. Write-Host $date.Substring(5,2)
  57. Write-Host $date
  58. #$usersToBlock = $userList | Where-Object { $_.current_sign_in_at -lt $goodDate }
  59. #Write-Output $usersToBlock.name
  60.  
  61. #foreach ($user in $usersToBlock){
  62. # Post-GitLabResource "api/v4/users/$($user.id)/block"
  63. #}
  64. }
  65. finally{
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement