Last active
May 15, 2024 08:17
-
-
Save EECOLOR/9da4c9ff1c7d7b55d8612026379e9186 to your computer and use it in GitHub Desktop.
List users and roles of all projects in csv for Google Cloud
This file contains 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
#!/bin/bash | |
outfile="./iam-policy.csv" | |
echo "Project, Account, Role" > $outfile | |
for project in $(gcloud projects list --format="table(projectId)" --filter 'parent.id=... AND parent.type=organization' | tail -n +2 | cut -f2 -d$' ' | sed '/^$/d'); do | |
out=$(gcloud projects get-iam-policy $project --flatten="bindings[].members[]" --format="csv[no-heading](bindings.members,bindings.role)") | |
echo $project | |
for line in $out; do | |
echo "$project,$line" >> $outfile | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment