Running Powershell script against all Azure subscriptions

Hi there

We have multiple subscriptions in our Azure tenant. I’m writing a PS script to update some properties in Azure and would like it to run across all subscriptions. Below is my script. Because we use multi-factor authentication I get prompted to log in and also have to choose a subscription, so my code below will only work for storage accounts in the subscription I choose at the start. I can get around the prompt for credentials by configuring a system identity token but the main thing I’m trying to resolve is how to get this to loop through my subscriptions successfully. Anyone done something similar?

Connect-AzAccount 

[System.Collections.ArrayList]$azureData = Import-Csv -Path .\SA_RG_Prod.csv

Foreach ($item in $azureData) {

    [String]$rgName = $item.RG
    [String]$saName = $item.SA

    # Change the storage account tier to cool
    Set-AzStorageAccount -ResourceGroupName $rgName -Name $saName -AccessTier  Cool

}

Thanks in advance!
Doodles

Hey Doodles,

I hope this helps because I’m not familiar with managing subscriptions and such but you can use Set-AzContext. It sets the tenant, subscription, and environment for cmdlets to use in the current session. If you need to get the subscription ID’s you can use Get-AzSubscription.