4
votes

We require an PowerShell script to find which Resource Group is not having IAM Role Assigned.

Please find below the PowerShell scripts for your reference, and let me know the PowerShell script for to finding which Resource Group is not having IAM Role Assigned.

Inviting Multiple Uers.

Install-Module AzureADPreview Connect-AzureAD -TenantId $invitations = import-csv C:\Users\dummy\Desktop\users.csv $messageInfo = New-Object Microsoft.Open.MSGraph.Model.InvitedUserMessageInfo $messageInfo.customizedMessageBody = "Hello. You are invited to the xyz.onmicrosoft.com." foreach ($email in $invitations)
{New-AzureADMSInvitation -InvitedUserEmailAddress $email.InvitedUserEmailAddress -InvitedUserDisplayName $email.Name -InviteRedirectUrl https://myapps.microsoft.com -InvitedUserMessageInfo $messageInfo ` -SendInvitationMessage $true }

Creating multiple resource groups.

Connect-AzureRmAccount -Tenant -Subscription import-csv C:\Users\dummy\Desktop\excel02.csv | ForEach-Object {New-AzureRmResourceGroup -Name $_.Name -Location centralIndia

Assigning iam role in bulk

Connect-AzureRmAccount -Tenant -Subscription import-csv C:\Users\dummy\Desktop\excel05.csv | ForEach-Object {New-AzureRMRoleAssignment -SignInName $.Users -RoleDefinitionName "Owner" -ResourceGroupName $.RG}

Getting Role Assignment in bulk.

Connect-AzureRmAccount -Tenant -Subscription #Get-AzureRmRoleAssignment -ResourceGroupName MridulAggarwal -SignInName [email protected] import-csv C:\Users\nawabjanm\Desktop\excel05.csv | ForEach-Object {Get-AzureRmRoleAssignment -ResourceGroupName $.RG -SignInName $.Users} | FL > D:\r20.csv

1

1 Answers

2
votes

Please find the below script to determine the resource groups with role assignments and their details in a particular subscription. So, those resource groups which are not listed in below are surely the ones which do not have any IAM role assignments.

 Get-AzResourceGroup | ForEach-Object {Get-AzRoleAssignment -ResourceGroupName 
 $_.ResourceGroupName} | export-csv 'C:\res.csv' 

Thus, you can be rest assured of those resource groups with the IAM role assignments.

Please find below links for more information: -

https://docs.microsoft.com/en-us/powershell/module/az.resources/get-azresourcegroup?view=azps-6.3.0

https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-list-powershell