Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Is it possible to show displayNames when using gcloud asset search-all-iam-policies

Hi,

I'd like to create a report on IAM policies as a CSV file. I'm listing the organization, plus resources, members and roles with the following command:

gcloud asset search-all-iam-policies --scope=organizations/012345678901 --flatten='policy.bindings[].members[]' --format='csv(organization.basename(), resource, policy.bindings.members, policy.bindings.role)'

In the output, the first column shows the organization ID.

Is it possible to show the organization displayName instead of the ID?

Thanks

Solved Solved
1 2 868
1 ACCEPTED SOLUTION

Not directly in that single gcloud command because it does not return that field, but you can look up the displayName using something like:

gcloud organizations list --filter=012345678901 --format="value(displayName)"

So if you're in  a bash shell you could combine them together with sed to do something like this:

DISPLAYNAME=$(gcloud organizations list --filter=012345678901 --format="value(displayName)"); gcloud asset search-all-iam-policies --flatten='policy.bindings[].members[]' --format='csv(organization.basename(), resource, policy.bindings.members, policy.bindings.role)' | sed "s/^012345678901/$DISPLAYNAME/"

That should be all one line 🙂

Hope that helps.

View solution in original post

2 REPLIES 2

Not directly in that single gcloud command because it does not return that field, but you can look up the displayName using something like:

gcloud organizations list --filter=012345678901 --format="value(displayName)"

So if you're in  a bash shell you could combine them together with sed to do something like this:

DISPLAYNAME=$(gcloud organizations list --filter=012345678901 --format="value(displayName)"); gcloud asset search-all-iam-policies --flatten='policy.bindings[].members[]' --format='csv(organization.basename(), resource, policy.bindings.members, policy.bindings.role)' | sed "s/^012345678901/$DISPLAYNAME/"

That should be all one line 🙂

Hope that helps.

Perfect, this is very helpful, thanks!