Your code sample suggests you want the answer in PowerShell. Here are some pointers:
Does:
Project ID
Account Name
Enabled| Disabled
Email
Keys
Timestamps
Doesn't:
Role Assignments
Last Used
PROJECTS=$(gcloud projects list --format="value(projectId)")
for PROJECT in ${PROJECTS}
do
echo "Project: ${PROJECT}"
# Extracts ACCOUNT_ID, EMAIL (==ACCOUNT_ID@...), DISABLED
ROBOTS=$(\
gcloud iam service-accounts list \
--project=${PROJECT} \
--format="csv[no-heading](displayName.encode(\"base64\"),email,email.split(\"@\").slice(0),disabled)")
for ROBOT in ${ROBOTS}
do
# Parse results
IFS=, read ENCODED_NAME EMAIL ACCOUNT_ID DISABLED <<< ${ROBOT}
NAME=$(echo -e ${ENCODED_NAME} | base64 --decode)
echo " Service Account: ${NAME}"
echo " Disabled: ${DISABLED}"
echo " Email: ${EMAIL}"
# Keys
KEYS=$(\
gcloud iam service-accounts keys list \
--iam-account=${EMAIL} \
--project=${PROJECT} \
--format="value(name.scope(keys))")
for KEY in ${KEYS}
do
echo " Key: ${KEY}"
done
# Creation (Only searches back 30-days!)
FILTER=""\
"logName=\"projects/${PROJECT}/logs/cloudaudit.googleapis.com%2Factivity\" "\
"resource.type=\"service_account\" "\
"protoPayload.methodName=\"google.iam.admin.v1.CreateServiceAccount\" "\
"protoPayload.request.account_id=\"${ACCOUNT_ID}\" "
LOG=$(\
gcloud logging read "${FILTER}" \
--project=${PROJECT} \
--format=json \
--freshness=30d \
--format="value(timestamp)")
echo " Created: ${LOG}"
done
done
If you need to know more about Cloud Computing, We recommend joining Cloud Computing Course today.