A few days ago, I was using Windows Azure PowserShell cmdlets to create a new virtual machine, and I got an error that didn’t provide the exception details. I requested some help internally and could eventually have additional information on my exception. Here what I did. | Il y a quelques jours, j’%u00e9tais en train d’utiliser les cmdlets PowerShell Windows Azure pour cr%u00e9er une nouvelle machine virtuelle, et j’ai eu une erreur qui ne donnait pas les d%u00e9tails de l’exception. J’ai demand%u00e9 de l’aide en interne et ai finalement pu obtenir le d%u00e9tail de l’exception. Voici ce que j’ai fait. |
The script and the exception I had were the following: | Le script et l’exception que j’avais %u00e9taient les suivants: |
PS C:\> $advm1 = New-AzureVMConfig -Name $vmName -InstanceSize Small -ImageName $imgName |
>> Add-AzureProvisioningConfig -WindowsDomain -Password $adminPassword -Domain $myDomain `
>> -DomainPassword $domainPassword -DomainUserName $domainUser -JoinDomain $FQDomainName |
>> Set-AzureSubnet -SubnetNames $subNet
>>
PS C:\>
PS C:\> New-AzureVM -VNetName $myVNET -ServiceName $serviceName -VMs $advm1
New-AzureVM : The remote server returned an unexpected response: (400) Bad Request.
At line:1 char:1
+ New-AzureVM -VNetName $myVNET -ServiceName $serviceName -VMs $advm1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureVM], ProtocolException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.IaaS.PersistentVMs.NewAzureVMCommand
The help I got internally stated that $Error[0].Exception was my ProtocolException and I also had some sample C# code that showed how to get the response stream that contains the interesting exception message. | On m’a indiqu%u00e9 en interne que ma ProtocolException se trouvait %u00eatre $Error[0].Exception et on m’a %u00e9galement fourni du code C# qui montrait comment obtenir le flux qui contenait le message int%u00e9ressant de l’exception. |
So I did the following: | Ainsi, j’ai proc%u00e9d%u00e9 comme suit: |
PS C:\> $sr = new-object System.IO.StreamReader($Error[0].Exception.InnerException.Response.GetResponseStream())
PS C:\> $txt = $sr.ReadToEnd()
PS C:\> $txt
<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>BadR
equest</Code><Message>The name is not a valid storage account name.</Message></Error>
PS C:\> $sr.Dispose()
So I could add the “MediaLocation“ to my “New-AzureVMConfig” to have my virtual machine created. | J’ai pu ensuite ajouter le param%u00e8tre “MediaLocation” %u00e0 ma “New-AzureVMConfig” et ai ainsi pu cr%u00e9er ma machine virtuelle. |
Blog Post by: Benjamin GUINEBERTIERE