Actually, I trying to run below PowerShell script which will tell me about the Role Assignments in my Azure Subscription:-
$tenantId = "xxxxxx"
$subscriptionId = "xxxxxxx"
# Log in to Azure withtenant and subscription IDs
Connect-AzAccount -Tenant $tenantId -Subscription $subscriptionId -UseDeviceAuthentication
#Role Assignment Function
Function Function-RoleAssignments(){
Write-Host "'n> Checking IAM Role Assignments…'n" -ForegroundColor Green
$Global:RoleAssignments = [System.Collections.ArrayList]::new()
$RoleAssignment = Get-AzRoleAssignment -Scope ("/subscriptions/"+Sglobal:SourceSubscription )
foreach($role in $RoleAssignment){
$csvObject = New-Object PSObject
Add-Member -inputObject $csv0bject -memberType NoteProperty -name "Display Name" -value$role.DisplayName
Add-Member -inputObject $csvObject -memberType NoteProperty -name "SignIn Name" -value $role.SignInliame
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 $csv0bject -memberType NoteProperty -name "Role" -value $role. RoleDefinitionName
Add-Member -inputObject $csv0bject -memberType NoteProperty -name "RoleDefinition ID" -value $role. RoleDefinitionId
Add-Member -inputObject $csvObject -memberType NoteProperty -name "Scope" -value $role.Scope
Add-Member -inputObject $csv0bject -memberType NoteProperty -name "Description" -value $role. Description
Add-Member -inputObject $csv0bject -memberType NoteProperty -name "CanDelegate" -value $role. CanDelegate
$Global:RoleAssignments.Add($csvObject) | Out-Null
}
}
# Call the function to populate SGlobal:RoleAssignment
Function-RoleAssignments
# Export the collected quota information to a CSV file SGlobal:RoleAssignments | Export-Csv -Path "RoleAssignment.csv" -NoTypeInformation
Write-Host "Resource report generated and saved to RoleAssignment.csv"
After running the script I faced the below error:-
Kindly help me how to solve this issue. Thank you in advance:)