我有十几个订阅,很难同时输出来自所有订阅的所有资源的所有角色分配。我目前正在使用下面的那个,但是每个 csv 文件的每个订阅都会循环输出。我如何最好将输出输出到一张纸上?
Get-AzSubscription | foreach-object {
Write-Verbose -Message "Changing to Subscription $($_.Name)" -Verbose
Set-AzContext -TenantId $_.TenantId -SubscriptionId $_.Id -Force
$Name = $_.Name
$TenantId = $_.TenantId
$SubId = $_.SubscriptionId
Get-AzRoleAssignment -IncludeClassicAdministrators | Select-Object RoleDefinitionName,DisplayName,SignInName,ObjectType,Scope,
@{name="TenantId";expression = {$TenantId}},@{name="SubscriptionName";expression = {$Name}},@{name="SubscriptionId";expression = {$SubId}} -OutVariable ra
# Also export the individual subscriptions to excel documents on your Desktop.
# One file per subscription
$ra | Export-Csv -Path C:\scripts\Export-AzRoleAssignment\$Name.csv -NoTypeInformation
}