0

I want to deploy a web role to Azure using the PowerShell CmdLets.

My script is as follows:

$subscription = "<name-of-subscription>"
$service = "<name-of-cloudservice>"
$slot = "staging"
$package = "path\to\package.cspkg"
$configuration = path\to\config.cscfg"
$deploymentLabel = "Deploy to $service"

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
Import-AzurePublishSettingsFile "C:\path-to.publishsettings"
Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscription

# some more stuff to check whether to upgrade or to create ...

Set-AzureDeployment -Upgrade -Slot $slot -Package $package -Configuration $configuration -label $deploymentLabel -ServiceName $service -Force

When I execute this it throws an error:

Exception: The subscription named <name-of-subscription> already exists.

I figured that since I'm importing my publishsettings-file already I could get rid of Set-AzureSubscription. However, once I do that I get the next error:

Exception: CurrentStorageAccountName is not set. 
Use Set-AzureSubscription subname -CurrentStorageAccountName storageaccount to set it. 

This is the line that gave me the error in the first place, so I'm not sure how I need to set the storageaccountname without causing an error.

I also ran a little test:

Import-AzurePublishSettingsFile "C:\path-to.publishsettings"

Get-AzureSubscription | Format-Table

Once I do this I get the following output (reformatted):

SubscriptionName:        <name-of-subscription>
SubscriptionId:          123456789-123...
ServiceEndpoint:         https://man....
ActiveDirectoryEndpoint:  
ActiveDirectoryTenantId:
IsDefault:               True 
Certificate              [Subject]
CurrentStorageAccountName 
CurrentCloudStorageAccount 
ActiveDirectoryUserId

As you can see, the CurrentStorageAccountName is empty, but I don't know how I can set it to a correct value.

I looked up some other scripts, but they all seem to be having this sequence of importing, then setting. Any idea why this is not working and how to solve it?

Kenneth
  • 28,294
  • 6
  • 61
  • 84

4 Answers4

1

You are trying to set CurrentStorageAccount to the name of your cloudservice, but you should be setting it to the name of your blob storage account. Get the list of you storage accounts

PS U:\>Get-AzureStorageAccount |select StorageAccountName 

StorageAccountName
------------------
portalvhdsgsomething
storage1
storage2
storage3

then run your previously failing line but with the name of your storage account ie.

Set-AzureSubscription -CurrentStorageAccount storage2 -SubscriptionName $subscription

You can confirm your changes with

PS U:\>Get-AzureSubscription | select CurrentStorageAccount

CurrentStorageAccount      : storage2
Raf
  • 9,681
  • 1
  • 29
  • 41
0

You need to use -CurrentStorageAccountName as the parameter of Set-AzureSubscription.

Guang Yang
  • 327
  • 1
  • 4
  • 1
    That is what I have: `Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscription` – Kenneth Jan 30 '14 at 23:25
0

For Set-AzureSubscription the MSDN doc shows the -SubscriptionName parameter as parameter 1, not as named. The error message's suggested fix even implied that you needed to do Set-AzureSubscription <service> -CurrentStorageAccount <storage solution> Perhaps simply moving that will solve it?

Set-AzureSubscription -SubscriptionName $subscription -CurrentStorageAccount $service

Reference: http://msdn.microsoft.com/en-us/library/dn495189.aspx

TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56
  • I tried that as well, but the order doesn't seem to matter – Kenneth Jan 31 '14 at 00:10
  • Where exactly in your script is it throwing the error? – TheMadTechnician Jan 31 '14 at 00:14
  • When I don't do `Set-AzureSubscription` upon executing `Set-AzureDeployment`, otherwise on `Set-AzureSubscription` – Kenneth Jan 31 '14 at 00:20
  • Only other thing I can think of is that you have a different subscription as your 'current subscription' apart from what's in $subscription, perhaps it is defined as part of your file import? Try doing a `get-azuresubscription | set-azuresubscription -currentstorageaccountname $service` and see if that clears it up. If it does you may have conflicting subscription references. I'm out for the night, I'll see if I come up with any better ideas and check back tomorrow. – TheMadTechnician Jan 31 '14 at 00:33
  • No, when I do a Get-AzureSubscription it only shows that one, with an empty CurrentStorageAccount. Thanks for the help! Good night. – Kenneth Jan 31 '14 at 00:38
0

I have found out the reason. It appears that you cannot include the subscription name as a named parameter. Changing this line:

Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscription

to this line did the trick

Set-AzureSubscription $subscription -CurrentStorageAccount $service
Kenneth
  • 28,294
  • 6
  • 61
  • 84