I was going to set up a new azure environment for a new customer with a powershell script when I encountered the following error:
Get-AzureVNetConfig : Value cannot be null.
Parametername: subscriptionId
At line:1 char:1
+ Get-AzureVNetConfig
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-AzureVNetConfig], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVNetConfigCommand
It seems that I was too quick to start with the new environment. I had forgotten to download the latest publishsettings file which contains the new customer subscription.
What instead happened now was that it created a new subscription named “CUSTOMERNAME” with SubscriptionID blank.
I realized the mistake and downloaded the latest publishsettings file.
After the import I ran Get-AzureSubscription and then I had two subscriptions with the same name. The problem now was that every time I ran Select-AzureSubscription CUSTOMERNAME it would choose the wrong one with the empty SubscriptionId. Select-AzureSubscription only selects by name and not by subscription id.
There are two solutions. Since the result from Get-AzureSubscription is stored in a local file and the azure commands use the subscription id we can manage the source file or the publishsettings file.
Solution 1 (the nice one) – Edit WindowsAzureProfile.xml
Got to C:\Users\UserName\AppData\Roaming\Windows Azure Powershell and open WindowsAzureProfile.xml
Look for:
<Name>CUSTOMERNAME</Name>
<RegisteredResourceProviders xmlns:d4p1=”http://schemas.microsoft.com/2003/10/Serialization/Arrays” />
<ResourceManagerEndpoint>https://management.azure.com/</ResourceManagerEndpoint>
<SqlDatabaseDnsSuffix>.database.windows.net</SqlDatabaseDnsSuffix>
<SubscriptionId i:nil=”true”
Remove everything that is included in, and the section (be safe and take a copy first):
<AzureSubscriptionData>
….
</AzureSubscriptionData>
Save, restart your powershell and run Get-AzureSubscription again. And voila! The faulty subscription is gone.
Solution 2 (the ugly one) – Edit the publishsettings file
Open up the file and find the subscription name CUSTOMERNAME. Rename it to CUSTOMERNAME2, save and exit. Import the publishsettings file again.
If you now use Select-AzureSubscription CUSTOMER2 and run Get-AzureVNetConfig it will work.