<p>You can use the below command to get all the policy attached to an iam user. (You must be having permissions to list-users and list-user-policies before using the below commands)</p>

<pre><code>aws iam list-attached-user-policies --user-name username | jq -r '.AttachedPolicies[].PolicyArn' | awk -F'policy/' {'print $NF'}
</code></pre>

<p>(Make sure to replace <code>username</code> with some actual iam username in the above command)</p>

<p>If you want to get the list of all users and user-policies attached to those users, you can use the below one line command. The below command will get all the <code>iam users</code> and then will find the <code>user-policies</code> attached to that user and will put in a CSV file. The first column will contain <code>username</code> and second column will contain `policies separated by spaces. </p>

<pre><code>for u_name in $(aws iam list-users | jq -r '.Users[].UserName') ; do permissions="$(aws iam list-attached-user-policies --user-name ${u_name} | jq -r '.AttachedPolicies[].PolicyArn' | awk -F'policy/' {'print $NF'} | tr '\n' ' ')" ; echo "${u_name}, ${permissions}" &gt;&gt; iam_users.csv ; done
</code></pre>

CC BY-SA 4.0
2019-11-25T17:32:17.407Z
You saved my day ! cheers !
Jithin Kumar S
CC BY-SA 4.0
2019-11-25T17:04:20.697Z
2019-11-25T17:04:20.697Z
Samit
<p>If you are looking to get the results for a single user then you want <a href="https://docs.aws.amazon.com/cli/latest/reference/iam/list-attached-user-policies.html" rel="nofollow noreferrer">list-attached-user-policies</a>.  However, this will result in the value being returned as json.  To get it into a csv style format check out the guide on how to <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html" rel="nofollow noreferrer">control the CLI output</a>.  You should be able to get the output into a delimited format for programmatic parsing.  I do not believe you'll be able to generate an .xlsx file directly from the AWS CLI.</p>

CC BY-SA 4.0
2019-11-25T17:05:17.447Z
Yes, generating an excel file directly from aws-cli won't be possible. He need to use different parsing program for formatting.
Samit
CC BY-SA 4.0
2019-11-25T16:40:31.720Z
2019-11-25T16:40:31.720Z
Wesley Rolnick
<p>aws : A single command(aws-cli) to get the IAM user name with the what all permission he/she have , would be great if can be downloaded as an excel or csv ?</p>

<amazon-web-services><aws-cli>
AWS-CLI : to download IAM user with policy
Jithin Kumar S
# AWS-CLI : to download IAM user with policy

(Asked by: username_0 on 2019-11-25)

aws : A single command(aws-cli) to get the IAM user name with the what all permission he/she have , would be great if can be downloaded as an excel or csv ?

**Tags:** amazon-web-services, aws-cli


---

## 2 answers

### Answer by username_1 on 2019-11-25. Score: 1 | Accepted answer

You can use the below command to get all the policy attached to an iam user. (You must be having permissions to list-users and list-user-policies before using the below commands)
aws iam list-attached-user-policies --user-name username | jq -r '.AttachedPolicies[].PolicyArn' | awk -F'policy/' {'print $NF'}

(Make sure to replace username with some actual iam username in the above command)
If you want to get the list of all users and user-policies attached to those users, you can use the below one line command. The below command will get all the iam users and then will find the user-policies attached to that user and will put in a CSV file. The first column will contain username and second column will contain `policies separated by spaces. 
for u_name in $(aws iam list-users | jq -r '.Users[].UserName') ; do permissions="$(aws iam list-attached-user-policies --user-name ${u_name} | jq -r '.AttachedPolicies[].PolicyArn' | awk -F'policy/' {'print $NF'} | tr '\n' ' ')" ; echo "${u_name}, ${permissions}" >> iam_users.csv ; done

> **Comments:**
> **username_0**: You saved my day ! cheers !  

---

### Answer by username_2 on 2019-11-25. Score: 0

If you are looking to get the results for a single user then you want [list-attached-user-policies](https://docs.aws.amazon.com/cli/latest/reference/iam/list-attached-user-policies.html). However, this will result in the value being returned as json. To get it into a csv style format check out the guide on how to [control the CLI output](https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output.html). You should be able to get the output into a delimited format for programmatic parsing. I do not believe you'll be able to generate an .xlsx file directly from the AWS CLI.

> **Comments:**
> **username_1**: Yes, generating an excel file directly from aws-cli won't be possible. He need to use different parsing program for formatting.  

---

