Created
August 13, 2020 22:33
-
-
Save scbedd/8890aa3e6f9da89ad660a2be4866b1f8 to your computer and use it in GitHub Desktop.
Check GH Org Membership
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$users = "<comma separated list of github users>" | |
# notice that we substring(1). This is because if you grab the gh users from a codeowners file, there will be a leading @ | |
# the substring rips it off. | |
$filtered_users = $users.Split(",") | % {$_.Trim()} | ? { $_ } | % { $_.SubString(1) } | Select -Unique | |
$not_added = @() | |
$headers = @{ | |
"Content-Type" = "application/json" | |
"Authorization" = "token $($env:GH_TOKEN)" | |
"Accept" = "application/vnd.github.v3+json" | |
} | |
foreach($usr in $filtered_users) { | |
try { | |
Write-Host "https://api.github.com//orgs/MicrosoftDocs/members/$usr" | |
$response = Invoke-RestMethod -Method GET -Uri "https://api.github.com/orgs/MicrosoftDocs/members/$usr" -Headers $headers | |
} | |
catch { | |
Write-Host $_ | |
$not_added += $usr | |
} | |
} | |
Write-Host $not_added |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment