Auditing Azure Role Assignments with PowerShell

Managing role assignments in Azure can be a complex task, especially when dealing with multiple subscriptions and ensuring that only eligible users have the necessary permissions. In this blog post, we’ll walk through a PowerShell script that helps you audit Azure role assignments by retrieving all eligible role assignments across your subscriptions. This script is particularly useful for administrators who need to maintain a secure and well-organized Azure environment.

Script Breakdown

Connect to Azure

First, we need to connect to our Azure account using the Connect-AzAccount command. Make sure to replace xxxxxxxxxx with your actual tenant ID.

This command authenticates your session with Azure, allowing you to interact with your subscriptions and resources.

Get all enabled subscriptions

Next, we retrieve all enabled subscriptions in your Azure account using the Get-AzSubscription command.

This ensures that we only work with active subscriptions.

Initialize array for eligible Azure assignments

We initialize an empty array to store the eligible Azure role assignments.

This array will hold the data we collect from each subscription.

Loop through each subscription

We loop through each subscription, set the context to the current subscription, and retrieve the role eligibility schedules.

This section ensures that we gather role eligibility data from all active subscriptions.

Displaying results in Grid View

We select specific properties from the eligible Azure role assignments and display them in a grid view for easy viewing.

This command provides a user-friendly interface to review the collected data.

Export results to CSV (Optional)

Optionally, you can export the results to a CSV file for further analysis or record-keeping. Uncomment the lines and specify the desired file path to save the data.

This step is useful for creating reports or sharing the data with other team members.

Conclusion

In this blog post, we’ve walked through a PowerShell script that helps you audit Azure role assignments by retrieving eligible role assignments across your subscriptions. This script is a valuable tool for administrators looking to maintain a secure and well-organized Azure environment.

Script Source

Complete script as always is available for download on azure365addict GitHub. Feel free to customize the script to fit your specific needs and improve your device management processes. If you have any questions or need further assistance, feel free to reach out!

Happy scripting!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top