Get-AzRoleAssignment:范围“/subscriptions”应包含偶数个部分

问题描述 投票:0回答:1

实际上,我尝试运行下面的 PowerShell 脚本,该脚本将告诉我有关 Azure 订阅中的角色分配的信息:-

运行脚本后,我遇到以下错误:-

请帮我解决这个问题。

提前谢谢您:)

azure powershell azure-powershell azure-rbac
1个回答
0
投票

我在我的环境中尝试了相同的操作,但出现了如下所示的相同错误:

enter image description here

为了了解 Azure 订阅中的角色分配,我运行了下面修改后的 PowerShell 脚本:

$tenantId = "xxxxxxx"
$subscriptionId = "xxxxxxxx"

# Log in to Azure with tenant and subscription IDs
Connect-AzAccount -Tenant $tenantId -Subscription $subscriptionId -UseDeviceAuthentication

#Role Assignment Function
Function Function-RoleAssignments(){

    Write-Host "`n> Checking IAM Role Assignments..." -ForegroundColor Green
    $Global:RoleAssignments = [System.Collections.ArrayList]::new()
    $RoleAssignment = Get-AzRoleAssignment -Scope "/subscriptions/$subscriptionId"

    foreach($role in $RoleAssignment){
        $csvObject = New-Object PSObject
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "Display Name" -value $role.DisplayName
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "SignIn Name" -value $role.SignInName
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "Object Type" -value $role.ObjectType
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "Object ID" -value $role.ObjectId
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "Role" -value $role.RoleDefinitionName
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "RoleDefinition ID" -value $role.RoleDefinitionId
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "Scope" -value $role.Scope
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "Description" -value $role.Description
        Add-Member -inputObject $csvObject -memberType NoteProperty -name "CanDelegate" -value $role.CanDelegate

        $Global:RoleAssignments.Add($csvObject) | Out-Null
    }
}

# Call the function to populate $Global:RoleAssignment
Function-RoleAssignments

# Export the collected quota information to a CSV file
$Global:RoleAssignments | Export-Csv -Path "RoleAssignment.csv" -NoTypeInformation

Write-Host "Resource report generated and saved to RoleAssignment.csv"

输出

enter image description here

在 csv 文件中,检索并显示指定订阅的 IAM 角色分配,如下所示:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.