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?
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