Files
PSScripts/Get-AzureRoles.ps1
2024-10-05 12:23:48 -05:00

30 lines
824 B
PowerShell

# NOTE:
# Make sure you are logged into the az cli before running this
# Command: az login
# Get the JSON data from Azure CLI
$jsonData = az role definition list | ConvertFrom-Json
# Create an empty array to store the formatted strings
$formattedRoles = @()
foreach ($role in $jsonData) {
$roleType = if ($role.roleType -eq "BuiltInRole") { "Built-in role" } else { "Custom role" }
$formattedRole = @"
$roleType $($role.roleName)
Description $($role.description)
ID $($role.name)
"@
$formattedRoles += $formattedRole
}
# Join all formatted roles into a single string
$output = $formattedRoles -join "`n"
# Write the output to a text file
$output | Out-File -FilePath "azure_roles.txt" -Encoding UTF8
Write-Host "Azure roles have been written to azure_roles.txt"