1
votes

I am new to Powershell, I am running following script and getting the error as mentioned in the subject line:

$LocationName = "West Europe"
$VNet_ResourceGroupName = "Mydeveloper_resource_group"
$VM_ResourceGroupName = "MyDeveloperResourceGroup"
$PublicIpAddress = "[]"
$PrivateIpAddress = "10.199.120.30" 
$VirtualNetworkName = "developer_vnet"
$SubnetName = "MySubnet"
$SubnetId = "/subscriptions/....../resourceGroups/developer_resource_group/providers/Microsoft.Network/virtualNetworks/developer_vnet/subnets/MySubnet"
$VMName = "AWE4DVM022"
$VMSize = "Standard_D4s_v3"
$AllocationMethod = "Static"
$ImageId = "/subscriptions/................................./resourceGroups/MyIMAGELIBRARY/providers/Microsoft.Compute/images/developer-desktop-image-...................." 

$cred = Get-Credential -Message "Type the name and password of the local administrator account."

$nic = New-AzureRmNetworkInterface -Name TestNIC -ResourceGroupName $VM_ResourceGroupName -Location $LocationName -SubnetId $SubnetId -PrivateIpAddress $PrivateIpAddress

$vm = New-AzureRmVMConfig -VMName $VMName -VMSize $VMSize

$vm = Set-AzureRmVMOperatingSystem -VM $vm -Linux -ComputerName $VMName -Credential $cred

$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id 

New-AzureRmVM -ResourceGroupName $VM_ResourceGroupName -ImageName $ImageId -VM $vm
1
Welcome to Stack Overflow! Please take the tour. You might want to specify your question a little: What are you trying to achieve? Which line is throwing the error? - Dux

1 Answers

4
votes

Powershell has this concept of parameter sets. When you call a script, function, or commandlet that uses parameter sets (like New-AzureRMVM does), you can't pass parameters for arguments in different sets. For example, New-AzureRmVM has three parameters sets. ResourceGroupName is in parameter sets 1, 2, and 3. ImageName is in parameter set 1, and VM is in parameter set 2. Powershell can't figure out what set to use because ImageName is on one set while VM is in another.