0
votes
################### Resource Group ###################


$rg = New-AzResourcegroup -Name "vlab3rg1" -Location "EastUS"
$rgname = $rg.ResourceGroupName 


################# Network Security group ####################

$rule1 = New-AzNetworkSecurityRuleConfig -Name "Allow_RDP" -Protocol * -SourceAddressPrefix * -DestinationAddressPrefix * `
-SourcePortRange * -DestinationPortRange 3389 -Access Allow -Priority 100 -Direction Inbound 

$nsg = New-AzNetworkSecurityGroup -Name vmlab3nsg -Location "EastUS" -ResourceGroupName $rgname -SecurityRules $rule1 


################### Create VNET and Subnet ###################

$subnet = New-AzVirtualNetworkSubnetConfig -Name subnet1  -AddressPrefix "10.0.1.0/27" -NetworkSecurityGroup $nsg 

$vnet = New-AzVirtualNetwork -Name vmlab3vnet -ResourceGroupName $rgname -Location "EastUS" -AddressPrefix "10.0.1.0/24" -Subnet $subnet 




######### Create public ip ####################################


$publicip = New-AzPublicIpAddress -Name publiciplb -ResourceGroupName $rgname -Location "EastUS" -Sku Standard -AllocationMethod Static 


############ Create Lad balancer #################


$fronendip = New-AzLoadBalancerFrontendIpConfig -Name "frondendip_lb" -PublicIpAddress $publicip 

$backendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name "myBackEndPool"

$natpool1 = New-AzLoadBalancerInboundNatPoolConfig -Name "nat_rdp" -Protocol TCP -FrontendPortRangeStart 3389 -FrontendPortRangeEnd 50001 -BackendPort 50010 -FrontendIpConfigurationId $fronendip.Id

$lb = New-AzLoadBalancer -ResourceGroupName $rgname -Name lb_rdp -Location 'EastUS'  -FrontendIpConfiguration $fronendip -BackendAddressPool $backendPool -InboundNatPool $natpool1 -sku Standard 



############### Create vm #################

$ipConfig = New-AzVmssIpConfig `
  -Name "myIPConfig" `
  -LoadBalancerInboundNatPoolsId $lb.BackendAddressPools[0].Id `
  -SubnetId $vnet.Subnets[0].Id `


$vmconfig = New-AzVmssConfig -Location "EastUS" -SkuCapacity 1 -SkuName "Standard_DS2" -UpgradePolicyMode Automatic

 Set-AzVmssStorageProfile $vmconfig  `
  -OsDiskCreateOption "FromImage" `
  -ImageReferencePublisher "MicrosoftWindowsServer" `
  -ImageReferenceOffer "WindowsServer" `
  -ImageReferenceSku "2016-Datacenter" `
  -ImageReferenceVersion "latest" `


 Set-AzVmssOsProfile  $vmconfig `
 -AdminUsername "admin123" `
 -AdminPassword "W3lcome_123456" `
 -ComputerNamePrefix "vmlab3w1" 

 Add-AzVmssNetworkInterfaceConfiguration `
 -Name network_config  `
 -VirtualMachineScaleSet $vmconfig `
 -Primary $true `
 -IpConfiguration $ipConfig



New-AzVMss -ResourceGroupName $rgname  -VMScaleSetName "VMSSKArt" -VirtualMachineScaleSet $vmconfig 

Output:

New-AzVMss : Cannot parse the request.
ErrorCode: InvalidRequestFormat
ErrorMessage: Cannot parse the request.
ErrorTarget: StatusCode: 400
ReasonPhrase: Bad Request OperationID : 7f540760-4e1a-49aa-9ec9-eb33204bdcdd At line:1 char:1
+ New-AzVMss -ResourceGroupName $rgname -VMScaleSetName "VMSSKArt" -Vi ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzVmss], ComputeCloudException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.Automation.NewAzureRmVmss

1

1 Answers

0
votes

You have a mistake in your $ipConfig, it should be the following:

$ipConfig = New-AzVmssIpConfig `
  -Name "myIPConfig" `
  -LoadBalancerInboundNatPoolsId $lb.InboundNatPools[0].id `
  -LoadBalancerBackendAddressPoolsId $lb.BackendAddressPools[0].Id `
  -SubnetId $vnet.Subnets[0].Id

so actually 2 mistakes :)

ps. figured that out with the following:

New-AzVMss -ResourceGroupName $rgname -VMScaleSetName VMSSKArt -VirtualMachineScaleSet $vmconfig -Debug