Skip to content

Instantly share code, notes, and snippets.

@1ARdotNO
Created December 18, 2024 09:12
Show Gist options
  • Save 1ARdotNO/804016848cd84188282e64d40b8259a2 to your computer and use it in GitHub Desktop.
Save 1ARdotNO/804016848cd84188282e64d40b8259a2 to your computer and use it in GitHub Desktop.
Script to use graphql api to fetch a list of emails and usernames from github,
param (
[Parameter(Mandatory = $true)] $orgName
)
$pat = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($ENV:GITHUB_TOKEN)"))
$query="{
organization(login: `"$orgName`") {
samlIdentityProvider {
externalIdentities(first: 100) {
nodes {
user {
login
name
email
}
samlIdentity {
attributes {
name
value
}
emails {
primary
type
}
}
}
}
}
}
}"
$params = @{
'Uri' = ('https://api.github.com/graphql')
'Headers' = @{'Authorization' = 'Basic ' + $pat }
'Method' = 'post'
'ContentType' = 'application/json'
'Body' = ( @{query=$query} | ConvertTo-Json )
}
#add environments
$result=Invoke-RestMethod @params
$result.data.organization.samlIdentityProvider.externalIdentities.nodes | ForEach-Object {
[pscustomobject]@{
name = ($_.samlidentity.attributes | where {$_.name -like "*displayname*"}).value
username = $_.user.login
email = ($_.samlidentity.attributes | where {$_.name -like "*emailaddress*"}).value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment