Pulling data from GitHub using PowerShell

Viewed 107

I am running the following script to get all my org users from GitHub. The script doesn't expand any system objects until I remove the FollowRelLink flag. It runs without any issues and all the fields are populated correctly, but I only get a few users if I don't use FollowRelLink. How can I get all users without using FollowRelLink because certainly GitHub API doesn't like that?

I am using PowerShell 7 and have couple other similar scripts that work without any issues with FollowRelLink.

Thanks in advance!

Code:

$token = <token>
$url = 'https://api.github.com/orgs/<org>/members'
$headers = @{Authorization = "bearer $token"}
$userCsv = "C:\temp\github-users-$(Get-Date -Format "MMddyyyy").csv" 

$UserList = Invoke-RestMethod -uri $url -Method 'GET' -headers $headers -FollowRelLink -ResponseHeadersVariable r -StatusCodeVariable s 

$UserOutput = $UserList | ForEach-Object { 
    
        [PSCustomobject]@{
        "Login"         = $_.login
        "Login ID"      = $_.id
        "Node ID"       = $_.node_id
        "Type"          = $_.type
        "Admin"         = $_.site_admin
        "Avatar"        = $_.avatar_url
        "Gravatar"      = $_.gravatar_id
        "URL"           = $_.url
        "HTML URL"      = $_.html_url
        "Followers URL" = $_.followers_url
        "Following URL" = $_.following_url
        "Gists URL"     = $_.gists_url
        "Starred URL"   = $_.starred_url
        "Subscriptions URL" = $_.subscriptions_url
        "Organizations URL" = $_.organizations_url
        "Repos URL"         = $_.repos_url
        "Events URL"        = $_.events_url
        "Received Events URL" = $_.received_events_url
        "Role ID" = ($_.id) -join ', '      
    
    }    
}

$UserOutput | Sort-Object -Property "Login" |
    Export-CSV -Path $userCsv -Force -NoTypeInformation
0 Answers
Related