Looping through Azure subscriptions with powershell

Template/building block for looping through Azure subscriptions. Can be used to perform certain operations in defined set of subscriptions. Can loop all subscriptions or defined set of them (comma separated list).

$subID_Param  is defining scope of looping. If it is equal to “” – it will loop through all subscriptions in tenant. If it has comma separated list of subscriptions ID – it will loop througt subscriptions specified in this list.

As an example code of payload to be executed on each subscription i choose simple VM inventory – getting list of all VMs in subscriptions with parameters like vm name, running status, VM size. It collects data to global variable of PSOobject type and save it’s contents to CSV file. This is simplified version of my global VM inventory script which i plan to publish later.

Code can be downloaded from github. Here is link

Leave a Reply

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