<p>Ran into this requirement recently as well. You can achieve this without the use of the <code>assets</code> API.</p>
<pre><code>$ gcloud projects get-iam-policy $PROJECT --flatten=&quot;bindings[].members&quot; --filter=&quot;bindings.role:roles/owner&quot; --format='table(bindings.members)'
</code></pre>

CC BY-SA 4.0
2022-07-06T00:40:35.160Z
2022-07-06T00:40:35.160Z
Matthew
<p>That can be achieved using another <code>gcloud</code> command:</p>

<pre><code>gcloud beta asset search-all-iam-policies --query policy:"roles/owner" --project $your_project_id --flatten="results[].policy[]" --format="csv(bindings.members[0])"
</code></pre>

CC BY-SA 4.0
2020-04-24T13:36:13.637Z
Yet another awkward and annoying inconsistency in gcloud. Docs link for reference: https://cloud.google.com/sdk/gcloud/reference/beta/asset/search-all-iam-policies
SiliconMind
CC BY-SA 4.0
2020-04-24T02:05:02.707Z
2020-04-24T02:05:02.707Z
manasouza
<p><code>gcloud projects get-iam-policy [PROJECT-ID]</code> lists all users with their roles for specific project. There are different filters and formatters available but I can't seem to find the right way to just filter only by specific role.</p>

<pre><code>$ gcloud projects get-iam-policy MY_PROJECT

bindings:
- members:
  - serviceAccount:12345678-compute@developer.gserviceaccount.com
  - user:alice@foobar.com
  role: roles/editor
- members:
  - user:you@yourdomain.com
  - user:someoneelse@yourdomain.com
  role: roles/owner
etag: ARBITRARY_ETAG_HERE
version: 1
</code></pre>

<p>What's the <code>--filter=</code> expression that I need to use to list only users with the role <code>roles/owner</code>?</p>

CC BY-SA 4.0
2021-06-22T12:02:53.387Z
I have a similar [question](https://devops.stackexchange.com/questions/14210/how-to-filter-all-roles-with-specific-user-in-gcp) but I want to filter by member-name. The `--query` thing does not help
KargWare
<google-cloud-platform><gcp>
How to list all users with specific role in GCP
SiliconMind
# How to list all users with specific role in GCP

(Asked by: username_0 on 2020-04-09)

gcloud projects get-iam-policy [PROJECT-ID] lists all users with their roles for specific project. There are different filters and formatters available but I can't seem to find the right way to just filter only by specific role.
$ gcloud projects get-iam-policy MY_PROJECT

bindings:
- members:
  - serviceAccount:12345678-compute@developer.gserviceaccount.com
  - user:alice@foobar.com
  role: roles/editor
- members:
  - user:you@yourdomain.com
  - user:someoneelse@yourdomain.com
  role: roles/owner
etag: ARBITRARY_ETAG_HERE
version: 1

What's the --filter= expression that I need to use to list only users with the role roles/owner?

**Tags:** google-cloud-platform, gcp

> **Comments:**
> **username_1**: I have a similar [question](https://devops.stackexchange.com/questions/14210/how-to-filter-all-roles-with-specific-user-in-gcp) but I want to filter by member-name. The `--query` thing does not help  

---

## 2 answers

### Answer by username_3 on 2020-04-24. Score: 3 | Accepted answer

That can be achieved using another gcloud command:
gcloud beta asset search-all-iam-policies --query policy:"roles/owner" --project $your_project_id --flatten="results[].policy[]" --format="csv(bindings.members[0])"

> **Comments:**
> **username_0**: Yet another awkward and annoying inconsistency in gcloud. Docs link for reference: https://cloud.google.com/sdk/gcloud/reference/beta/asset/search-all-iam-policies  

---

### Answer by username_2 on 2022-07-06. Score: 2

Ran into this requirement recently as well. You can achieve this without the use of the assets API.
$ gcloud projects get-iam-policy $PROJECT --flatten="bindings[].members" --filter="bindings.role:roles/owner" --format='table(bindings.members)'


---

