Forum Discussion
James_Daniel
May 14, 2024Copper Contributor
Azure subscription owners
Hi
Is there any script (Azure CLI) to get the list of owners of Azure subscription. We have a around 500 subscription. we need to get a owners of each subscription.
I've searched in Google but haven't got any script to specifically to get owners list.
James
2 Replies
Sort By
- AllenVisserCopper Contributorhowzit bud,
I have tested this script and it works 100%
#Connect to Azure
Connect-AzAccount
#part 1 - Retrieves all subscriptions that your account has RBAC permissions to access as well as SCOPED to access across your tenant.
#part 2 - Retrieves all the owners in each of the subscriptions via the RoleDefinitionId “8e3af657-a8ff-443c-a75c-2fe8c4bcb635” built-in Owner role.
#part 3 - Exports to a file location of your choice (Ive tested in Azure cli, so from there, simply download onto your local device 🙂
# Hope my solution works for you 🙂
$sublist = Get-AzSubscription
foreach ($item in $sublist) {
$scopeappend = "/subscriptions/" + $item.Id
$export = (Get-AzRoleAssignment -RoleDefinitionId "8e3af657-a8ff-443c-a75c-2fe8c4bcb635" -Scope $scopeappend |
where { ($_.ObjectType -EQ "user") -and ($_.Scope -EQ $scopeappend) }) |
select DisplayName, SignInName
}
$export | Export-Csv -Path ./owners.csv
##End of script### Try this:
Connect-AzAccount $sublist= Get-AzSubscription foreach ($item in $sublist){ $scopeappend= "/subscriptions/"+$item.Id $export=(Get-AzRoleAssignment -RoleDefinitionId "8e3af657-a8ff-443c-a75c-2fe8c4bcb635" -Scope $tdt | where {($_.ObjectType -EQ "user") -and ($_.Scope -EQ $scopeappend) } ) | select DisplayName,SignInName } $export|Export-Csv -Path C:\result.csv