Two scenarios not covered is if you already have a PowerShell profile that you want to edit and if you want to change the PowerShell profile for PowerShell ISE.
The easiest way to set your subscription in ARM is to use your PowerShell profile as 4c74356b41 points out.
To find the path to your PowerShell profiles use
$Profile | Format-List.
The Windows PowerShell profile is typically in ..\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
The PowerShell ISE profile is typically in ..\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
If either are missing use
New-Item -path $profile -type file –force from the ISE or PowerShell window to create an empty file.
If you want to list all PowerShell profile files with their path add the -Force switch
$Profile | Format-List -Force.
If you are using a Microsoft account, such as firstname.lastname@example.org, then add this to the .ps1 file
Login-AzureRmAccount -TenantId "Tenant ID" -SubscriptionId "Subscription ID". You can get a list of all Subscription and Tenant IDs using
Get-AzureRmSubscription | Format-List.
You could use APowerShell’s answer also, I prefer not to use the Subscription Name parameter. It isn’t uncommon for the sub name to change when you have multiple subs, the SubID and TenantID will not change.
If you are logging in using a work account like email@example.com then you can automate the entire login and subscription selection using something like this.
$AzureAcct = "firstname.lastname@example.org" $AzurePwd = ConvertTo-SecureString "P@s$w0rd" -AsPlainText -Force $AzureCreds = New-Object System.Management.Automation.PSCredential($AzureAcct, $AzurePwd) $Login-AzureRmAccount -Credential $AzureCreds -TenantId "Tenant ID" -SubscriptionId "Subscription ID"
If you only use the parameter
-SubscriptionId you can get login errors if the account has been added to multiple Azure subscriptions, so it is important to use
-TenantId as well.