Configure a Azure VM with two NIC's - powershell

I'm implementing a site-to-site VPN using Site-to-Site VPN in Azure Virtual Network using Windows Server 2012 Routing and Remote Access Service (RRAS).
To configure it, i need One Windows Server 2012 machine with two NIC.
Using Microsoft Azure Powershell,I'm trying to create it.
I am following the steps from this article at microsoft website.
I select the VM from Azure Image Gallery.
$image = Get-AzureVMImage -ImageName "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201408.01-en.us-127GB.vhd"
Then I create a VM configuration with its name, no.of cores(4), and image. I dont what is availabilityset.
$vm = New-AzureVMConfig -Name "MultiNicVM" -InstanceSize "ExtraLarge" -Image $image.ImageName –AvailabilitySetName “MyAVSet”
Create login for the VM.
Add-AzureProvisioningConfig –VM $vm -Windows -AdminUserName “” -Password “”
4.Add our Additional NIC with Static IP address
Add-AzureNetworkInterfaceConfig -Name "Ethernet1" -SubnetName "Midtier"
-StaticVNetIPAddress "10.1.1.111" -VM $vm
Configuration for Default NIC. For default NIC, it should be public IP, why it is given a private Ip?
Set-AzureSubnet -SubnetNames "Frontend" -VM $vm
Set-AzureStaticVNetIP -IPAddress "10.1.0.100" -VM $vm
Create your VM, with "MultiNIC-VNet" already exists as a Virtual Network.
New-AzureVM -ServiceName "MultiNIC-CS" –VNetName “MultiNIC-VNet” –VM $vm
At the Step 6, it get an error "hosted service does not exist"
New-AzureVM : ResourceNotFound: The hosted service does not exist.
At line:1 char:1
+ New-AzureVM -ServiceName "MultiNIC-CS" –VNetName “MultiNIC-VNet” –VM $vm
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewAzureVMCommand
All i need a NIC with public IP and a NIC with private IP which acts as a local area network for the site to site VPN. But the default NIC is given a private IP, a another NIC with public IP will be created automatically?
Why do i get an error "hosted service does not exist"?

Location or AffinityGroup parameter not being specified in New-AzureVM
(one of these is required when creating new service)

Related

VNet not found when attempting to create VNET integration via azureRM

I am attempting to configure the VNET of an app service. I am attempting to do this via a powershell script. I have been using the same powershell script for over a year and it has suddenly stopped working without any modifications to the script. The link that is failing is as follows:
$propertiesObject = #{
"vnetResourceId" = "/subscriptions/$($subscriptionId)/resourceGroups/$($vnetToaddResGroup)/providers/Microsoft.Network/virtualNetworks/$($vnetToAdd)"
}
New-AzureRmResource -Location $location -Properties $propertiesObject -ResourceName "$($WebApp)/$($vnetToAdd)/primary" -ResourceType "Microsoft.Web/sites/virtualNetworkConnections/gateways" -ApiVersion 2015-08-01 -ResourceGroupName $WebAppResourceGroup -Force
This then results in the following error:
New-AzureRmResource : {"Code":"NotFound","Message":"Cannot find Vnet with name
VNet-EUDEV02.","Target":null,"Details":[{"Message":"Cannot find Vnet with name
VNet-EUDEV02."},{"Code":"NotFound"},{"ErrorEntity":{"ExtendedCode":"51004","MessageTemplate":"Cannot find {0} with
name {1}.","Parameters":["Vnet","VNet-EUDEV02"],"Code":"NotFound","Message":"Cannot find Vnet with name
VNet-EUDEV02."}}],"Innererror":null}
At C:\Users\Andre\Desktop\Repos\devops-scripting\andre-script-remake\clusterswap.ps1:66 char:5
+ New-AzureRmResource -Location $location -Properties $propertiesOb ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : NotFound,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourc
eCmdlet
This is strange as I have checked the VNET exists, and also checked the the resource group, and have tried numerous other Vnets.
How can I add VNet integration via a powershell command using azureRM?
This command is trying to use Gateway-required VNet Integration. I guess you already have a gateway provisioned and intend to use it.
Looking at the command, one thing which stands out is this parameter
-ResourceName "$($WebApp)/$($vnetToAdd)/primary"
Refer this post on how to do this.
Additionally, there is a PS script here that can be used to provision the VPN gateway and then configure it with the Web App.
BTW, there are other options to consider.
If your resources are in the same region, then you could avoid additional costs associated with Gateways, by using Regional VNet Integration. This is super easy to setup. The CLI is available here
There is also NAT Gateway. See this for provisioning NAT Gateways
HTH

Enabling disk encryption fails for Azure Ubuntu 16.04-LTS saying "'VolumeType' is not supported"

Azure Disk Encryption for Windows and Linux IaaS VMs says that "Linux OS disk encryption is currently supported on ... Ubuntu 16.04" however when I create a new VM
$vm = New-AzureRmVMConfig -VMName "vmname" -VMSize "Standard_D2_v2"
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Linux -ComputerName "vmname" -Credential $cred
$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "16.04-LTS" -Version "latest"
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$osDiskUri = $storage_account.PrimaryEndpoints.Blob.ToString() + "vhds/vmname.vhd"
$vm = Set-AzureRmVMOSDisk -VM $vm -Name "myOsDisk1" -VhdUri $osDiskUri -CreateOption fromImage
New-AzureRmVM -ResourceGroupName "rgname" -Location "East US" -VM $vm
and then run
Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName "rgname" -VMName "vmname" -AadClientID "appname" -AadClientSecret "xxx=" -DiskEncryptionKeyVaultUrl $KeyVault.VaultUri -DiskEncryptionKeyVaultId $KeyVault.ResourceId;
then I get this error:
Set-AzureRmVMDiskEncryptionExtension : Long running operation failed with status 'Failed'.
ErrorCode: VMExtensionProvisioningError
ErrorMessage: VM has reported a failure when processing extension 'AzureDiskEncryptionForLinux'. Error message: "VolumeType "" is not supported".
StartTime: 6/01/2017 3:12:44 PM
EndTime: 6/01/2017 3:14:49 PM
OperationID: b976c3ab-fe5b-4356-b62f-96f3b80aeba1
This post suggests there may be some way to apply encryption earlier than this, but actually I think it relates to people with already-encrypted drives they are trying to move into Azure.
What am I doing wrong? How can I use PowerShell to enable disk encryption on Ubuntu?
For now, Azure does not support use Set-AzureRmVMDiskEncryptionExtension to encrypt Linux OS disk. Please refer to this article
-VolumeType
Specifies the type of virtual machine volumes to perform the encryption operation. Allowed values for virtual machines that run the Windows operating system are as follows: All, OS, and Data.
The allowed values for Linux virtual machines are as follows: Data only.
You need prepare a pre-encrypted Linux VHD and use the VHD to create an encrypted Linux VM on Azure.
Please refer to the following steps.
1.Create an Ubuntu 16.0.4 VM on Azure.
2.Prepare a pre-encrypted Linux VHD. Please refer to this article.Notes: You need prepare the VHD on-premise.
3.Upload VHD to Azure.
4.Use template to create an encrypted Linux VM on Azure.

Assigning a public ip address to an existing nic in Azure using powershell

Using Azure CLI, it's possible to create and assign a public ip address to an existing nic e.g.
Create a public ip in a given resource group and region
azure network public-ip create -g myresourcegroup -a Dynamic -l westus mypublicipname
Assign the pip created in previous step to an existing nic
azure network nic set -g myresourcegroup -p mypublicipname mynicname
However similar code in powershell doesn't work e.g.
Create a new pip (completes successfully)
$pip = New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic -Force
Assign to an existing nic
$nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name $nicName
$nic.IpConfigurations[0].PublicIpAddress = $pip.IpAddress
Last line doesn't work and throws the following error:
The property 'Id' cannot be found on this object. Verify that the property exists and can be set.
At line:31 char:9
+ $nic.IpConfigurations[0].PublicIpAddress.Id = $pip.Id
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Though intellisense in PS ISE does show Id property for both! Does anyone knows if this is supposed to work?
Thanks to Tim Wieman (MSFT) of AzureCAT for the solution! Basically you need to assign the newly created pip to nic's PublicIPAddress property and then run Set-AzureRmNetworkInterface command as below:
$nic.IpConfigurations[0].PublicIpAddress = $pip
Set-AzureRmNetworkInterface -NetworkInterface $nic

Creating a VM in Azure using Powershell

I am trying to create a VM in Azure using powershell. I am running this on my local PC. I have been able to setup websites and SQL Azure instances without any issues but None of the samples on the web work.
Import-Module Azure
Import-AzurePublishSettingsFile -PublishSettingsFile "C:\Cloud\Azure.publishsettings"
$VMImage = #(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName
$myVMName = "jsTestVM1"
$myAdminName ="jsTestAdmin1"
$myAdminPwd ="not telling you"
New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVMName -AdminUsername $myAdminName -Password $myAdminPwd -InstanceSize "ExtraSmall"
I get the following message:
New-AzureQuickVM : ResourceNotFound: The hosted service does not exist.
At line:1 char:1
+ New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVM ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureQuickVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM
I've tried samples from the web and they give the same error message as well.
Edit:
If I specify a location I get the error message 'Service already exists, Location cannot be specified'.
If I specify AffinityGroup I get 'Service already exists, AffinityGroup cannot be specified'
$VMImage = #(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName
$myVMName = "srikstest"
$myAdminName ="srikstest"
$myAdminPwd ="NeitherMe"
New-AzureQuickVM -Windows -ServiceName $myVMName -ImageName $VMImage -AdminUsername $myAdminName - Password $myAdminPwd -InstanceSize "ExtraSmall" -Location "Southeast Asia" -Name $myVMName -Verbose
You can create a new Azure service for the virtual machine by specifying either the Location or AffinityGroup parameters, or deploy the new virtual machine into an existing service.
I've just added the location parameter and it worked !!
In the end I added an affinity group and changed the service name I was using. This enabled me to create the VM. The service name I was using was not in use as far as I was aware in my subscription so either a previous failed install left some artefact around or the name needs to be globally unique. I've checked the docs here
http://msdn.microsoft.com/en-us/library/azure/dn495183.aspx
and it doesn't state the service name needs to be globally unique
Assign/replace the value to variable.
New-AzureVMConfig -Name $VmName -InstanceSize $InstanceSize -Label $VmName -ImageName $Imagename -DiskLabel $DiskLabel |
add-azureprovisioningconfig -LinuxUser $cred.GetNetworkCredential().Username -Linux -Password $cred.GetNetworkCredential().Password -SSHPublicKeys $sshkey |
Add-AzureEndpoint -LocalPort $LocalPort1 -Name $LocalPortName1 -Protocol tcp -PublicPort $LocalPort1 |
New-AzureVM -ServiceName $CloudServiceName -AffinityGroup $AffinityGroup –WaitForBoot

Assigning a reserved IP to a VM

I am trying to assign a reserved ip address to a newly created VM on Azure. I am following steps indicated here: https://azure.microsoft.com/en-us/documentation/articles/virtual-networks-reserved-public-ip/
Here is what I am doing and the error it throws:
## Create VM Config with a cloned VHD (no issues here)
$migratedVM = New-AzureVMConfig -Name 'IP-CLONE' -DiskName 'TEST-AgendaCondivisa-2014-05-28.vhd' -InstanceSize 'Small'
## Reserve an IP address
$ReservedIP = New-AzureReservedIP -ReservedIPName "IP-CLONE" -Label "IP-CLONE" -Location "Japan West"
##Create VM
New-AzureVM -ServiceName "IP-CLONE" -Location "West Europe" -VMs $migratedVM -ReservedIPName $ReservedIP
OperationDescription OperationId OperationStatus
-------------------- ----------- ---------------
New-AzureVM 933fe90c-e087-bc26-882d-f5c79148f23e Succeeded
New-AzureVM : BadRequest: The Reserved IP **Microsoft.WindowsAzure.Commands.ServiceManagement.Model.ReservedIPContext does not exist.**
At line:1 char:1
+ New-AzureVM -ServiceName "IP-CLONE" -Location "West Europe" -VMs $migratedVM -Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewAzureVMCommand
Needless to say, if I do not use the “-reservedipname” switch everything works fine and the VM gets created without throwing errors.
Any idea?
It looks like you're reserving an IP address in "Japan West" and trying to assign it to a new Azure VM to be created in "West Europe"
You must reserve an IP address from the same region you want to deploy your VM to
Reserve an IP address in "West Europe" or create your VM in "Japan West"