Showing posts with label Azure. Show all posts
Showing posts with label Azure. Show all posts

Wednesday, October 26, 2016

Missing ComputerName Field in Azure (ARM)

Have you noticed that some of your VMs in Azure ARM is missing a ComputerName field? All you get is a dash "-", like:


It turns out that you probably uploaded a non-generalized VHD (aka - it was not sysprepped). In Microsoft terms, this is also known as "specialized" VHD.

According to Microsoft, this is because the "OSProfile" field is missing, which is by design because this is a specialized image. One can only specify the OSProfile field when creating VMs using a generalized image.

Resolution: This is unfortunately a known issue and there is no way around it.

With a VM created from a specialized image the OSProfile field is set using the command "Set-AzureRMVMOperatingSystem". For example, to set it Windows, the following command is run:

Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows

For more information about specialized image and generalized images in Azure:

https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-create-vm-generalized/

https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-create-vm-specialized/

Tuesday, August 09, 2016

Error Creating Cross Subscription VNet-to-VNet Connection on Azure Resource Manager Using PowerShell

So you are trying to create a VNet to VNet connection across subscriptions in Azure Resource Manager. The official documentation states that this cannot done by portal, and only PowerShell is supported:

https://azure.microsoft.com/en-us/documentation/articles/vpn-gateway-vnet-vnet-rm-ps/

When you run the final piece of code to create the connection:

$vnet1gw = New-Object Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkGateway
$vnet1gw.Name = "VNet1GW"
$vnet1gw.Id   = "/subscriptions/b636ca99-6f88-4df4-a7c3-2f8dc4545509/resourceGroups/TestRG1/providers/Microsoft.Network/virtualNetworkGateways/VNet1GW "
New-AzureRmVirtualNetworkGatewayConnection -Name $Connection51 -ResourceGroupName $RG5 -VirtualNetworkGateway1 $vnet5gw -VirtualNetworkGateway2 $vnet1gw -Location $Location5 -ConnectionType Vnet2Vnet -SharedKey 'AzureA1b2C3'

You get the following error message:


UInt64 -> Nullable`1
System.UInt64 -> System.Nullable`1[[System.Int64, mscorlib .....

I was running Azure PowerShell 1.6.0 at the time.

Fix: Upgrade to Azure PowerShell 2.0.0 (download here).

To check your Azure PowerShell version, run the following script:

(Get-Module -ListAvailable | Where-Object{ $_.Name -eq 'Azure' }) `
| Select Version, Name, Author, PowerShellVersion  | Format-List;


Thursday, January 21, 2016

Deploying a Azure Resource Manager (ARM) JSON Template

For the non-developers in us, it's a lot more harder than it looks.


  1. Using Web Platform Install, install the following (https://www.microsoft.com/web/downloads/platform.aspx)
    1. Install Visual Studio Community 2015
      1. Make sure that the "Microsoft SQL Server Data Tools" is installed, if not, then you can add it later in Add/Remove Programs
    2. Install Azure Tools
    3. Install Azure PowerShell 1.0
  2. Run Visual Studio Community 2015 with Administrator rights - make sure it's admin rights or else your deployment (which runs Azure PowerShell in the background) will fail with very odd error messages! (See error below)
  3. Create new project
    1. File > New > Project > Installed > Templates > Visual Basic > Cloud > Azure Resource Group
  4. Pick a Azure Template, I recommend "Blank Template" from Microsoft to start with
  5. Under Solution Explorer (on right), expand Templates > azuredeploy.json
  6. Click "JSON Outline" on bottom left and start creating resources by clicking "Add Resource"
  7. When template is complete, right click on "AzureResourceGroup" under Solution Explorer and select Deploy.

If you forgot to run Visual Studio Community 2015 without admin rights, you will get the following cryptic messages:

14:04:09 - Build started.
14:04:09 - Project "AzureResourceGroup2.deployproj" (StageArtifacts target(s)):
14:04:09 - Project "AzureResourceGroup2.deployproj" (ContentFilesProjectOutputGroup target(s)):
14:04:09 - Done building project "AzureResourceGroup2.deployproj".
14:04:09 - Done building project "AzureResourceGroup2.deployproj".
14:04:09 - Build succeeded.
14:04:09 - The following parameter values will be used for this deployment:
14:04:09 - Launching deployment PowerShell script with the following command:
14:04:09 - 'c:\users\username\documents\visual studio 2015\projects\azureresourcegroup2\azureresourcegroup2\Scripts\Deploy-AzureResourceGroup.ps1' -StorageAccountName '' -ResourceGroupName 'RG_Test1' -ResourceGroupLocation 'southeastasia' -TemplateFile 'c:\users\username\documents\visual studio 2015\projects\azureresourcegroup2\azureresourcegroup2\templates\azuredeploy.json' -TemplateParametersFile 'c:\users\username\documents\visual studio 2015\projects\azureresourcegroup2\azureresourcegroup2\templates\azuredeploy.parameters.json' -ArtifactStagingDirectory '..\bin\Debug\staging'
14:04:09 - Get-AzureEnvironment : The term 'Get-AzureEnvironment' is not recognized as the name of a cmdlet, function, script 
14:04:09 - file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
14:04:09 - and try again.
14:04:09 - At line:1 char:174
14:04:09 - + ... zure_PS_Data_Collection = 'true' }; if ((Get-AzureEnvironment -Name ' ...
14:04:09 - +                                              ~~~~~~~~~~~~~~~~~~~~
14:04:09 -     + CategoryInfo          : ObjectNotFound: (Get-AzureEnvironment:String) [], CommandNotFoundException
14:04:09 -     + FullyQualifiedErrorId : CommandNotFoundException
14:04:09 -  
14:04:10 - Get-AzureEnvironment : The term 'Get-AzureEnvironment' is not recognized as the name of a cmdlet, function, script 
14:04:10 - file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct 
14:04:10 - and try again.
14:04:10 - At line:1 char:2183
14:04:10 - + ... user@company.com' -Environment (Get-AzureEnvironment -Name ' ...
14:04:10 - +                                              ~~~~~~~~~~~~~~~~~~~~
14:04:10 -     + CategoryInfo          : ObjectNotFound: (Get-AzureEnvironment:String) [], CommandNotFoundException
14:04:10 -     + FullyQualifiedErrorId : CommandNotFoundException
14:04:10 -  
14:04:10 - & : The script 'Deploy-AzureResourceGroup.ps1' cannot be run because the following modules that are specified by the 
14:04:10 - "#requires" statements of the script are missing: AzureRM.Resources.
14:04:10 - At line:1 char:2227
14:04:10 - + ... eCloud')));&'c:\users\username\documents\visual studio 2015\projects\ ...
14:04:10 - +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14:04:10 -     + CategoryInfo          : ResourceUnavailable: (Deploy-AzureResourceGroup.ps1:String) [], ScriptRequiresException
14:04:10 -     + FullyQualifiedErrorId : ScriptRequiresMissingModules
14:04:10 -  
14:04:10 - Deploying template using PowerShell script failed.
14:04:10 - Tell us about your experience at http://go.microsoft.com/fwlink/?LinkId=691202

So make sure you "Run as administrator"!