I've been trying to create a powershell script to create an Azuer firewall rule on the fly.
The code I'm using is:
$servername = "xxx"
$username = "[email protected]"
$password = "xxx"
$subscription = "Pay-As-You-Go"
$secpasswd = ConvertTo-SecureString
$password -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential ($userName, $secpasswd)
Login-AzureRmAccount -Credential $cred -SubscriptionName $subscription
Select-AzureSubscription -SubscriptionName $subscription -Default
$ipAddress = (Invoke-WebRequest 'http://myexternalip.com/raw').Content -replace "`n"
New-AzureSqlDatabaseServerFirewallRule -ServerName $servername -RuleName 'Test' -StartIpAddress $ipAddress -EndIpAddress $ipAddress
I also get the following errors:
Select-AzureSubscription : The subscription name Pay-As-You-Go doesn't exist.
and
New-AzureSqlDatabaseServerFirewallRule : No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.
I'm also tried changing the Login-AzureRmAccount to Add-AzureAccount but it didn't make any difference. The user I created is an owner of the SQL server.
Is there anything else I might be missing?