Skip to content

Instantly share code, notes, and snippets.

@EECOLOR
Last active May 15, 2024 08:17
Show Gist options
  • Save EECOLOR/9da4c9ff1c7d7b55d8612026379e9186 to your computer and use it in GitHub Desktop.
Save EECOLOR/9da4c9ff1c7d7b55d8612026379e9186 to your computer and use it in GitHub Desktop.
List users and roles of all projects in csv for Google Cloud
#!/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