0
votes

I have three subscription accounts in Azure and am using java to execute PowerShell commands for a remote app.

My PowerShell version:

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1

I have the following issues:

  1. I need to be able to work simultaneously in PowerShell from java on different Azure accounts.
  2. The Select-AzureSubscription command sets the account as default and current. However, if I use -Default on Select-AzureSubscription it says -Default is deprecated.
  3. After selecting a subscription I need all commands there after to work on the selected subscription.

How should I maintain these to work simultaneously on different subscriptions?

2

2 Answers

4
votes

Since it is not specified what version of Azure PowerShell modules you have installed, I would first suggest making sure you have the latest, which are available at http://aka.ms/webpi-azps.

The way to manage these multiple environments going forward (the new way) would be to use Azure profiles. For example (using fictitious names),

# Create a profile
Login-AzureRmAccount -SubscriptionId "[subscription id (GUID)]" -TenantId "adatum.onmicrosoft.com"
Save-AzureRmProfile -Path "C:\adatum"   # Use a name meaningful to you.

# Create another profile
Login-AzureRmAccount -SubscriptionId "[subscription id (GUID)]" -TenantId "contoso.com"
Save-AzureRmProfile -Path "C:\contoso"   # Use a name meaningful to you.

# Create another profile
Login-AzureRmAccount -SubscriptionId "[subscription id (GUID)]" -TenantId "fabrikam.com"
Save-AzureRmProfile -Path "C:\fabrikam"   # Use a name meaningful to you.

Then, select the profile you want to use for a session. For example,

Select-AzureRmProfile -Path "C:\contoso"
# Do work (invoke commands) on the Contoso tenant.

Select-AzureRmProfile -Path "C:\adatum"
# Do work (invoke commands) on the Adatum tenant.

and so on...

0
votes

@hari, According to your description, i am not sure what's service you want to manage it using PowerShell. For better to develop PowerShell script, I suggest you can install the PowerShell ISE.

If you want to use Service management API to manage your service, you can follow this method to set your subscription.

PS C:\Users\user> Add-AzureAccount

PS C:\Users\user> $subscriptionList=Get-AzureSubscription | fl SubscriptionName,SubscriptionId,IsDefault,IsCurrent

PS C:\Users\user> $subscriptionList
PS C:\Users\user> function DoAction($subscriptionID){ $subscriptionID}

PS C:\Users\user> function SubscriptionList($subscriptionList){ for($i=0;$i -lt $subscriptionList.Length;$i++){DoAction($subscriptionList[$i].SubscriptionId);$subscriptionList[$i].SubscriptionId}}

PS C:\Users\user> SubscriptionList -subscriptionList $subscriptionList

If you want to manage the Azure Resource Group, I recommend you use the azure ARM module to handler your operation as @Rick said on previous post. And you can code the function to execute your logic. I recommend you refer to this document:http://azurefabric.com/powershell-1-0-and-arm-tenants-and-subscriptions/