Share via


Cannot create VM with PowerShell - Parameter set cannot be resolved using the specified named parameters.

Question

Sunday, March 10, 2019 9:36 PM

I try to create 2 VMs, but I'm failing. What could be wrong with Powershell? First VM is for SQL Server. Second is for DC.

VNet, PublicIP, NSG, NICs have been successfully created.

# Create a SQL Server VM configuration
$FEVMName = "PBIVM"
$FEVMConfig = New-AzVMConfig -VMName $FEVMName -VMSize Standard_DS11_V2 | `
   Set-AzVMOperatingSystem -Windows -ComputerName $FEVMName -Credential $Cred -ProvisionVMAgent -EnableAutoUpdate | `
   Set-AzVMSourceImage -PublisherName "MicrosoftSQLServer" -Offer "SQL2017-WS2016" -Skus "SQLDEV" -Version "latest" | `
   Add-AzVMNetworkInterface -Id $frontendNic.Id

# Create the SQL Server VM
New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $FEVMConfig -SubnetName PBISubnet

# Create DC VM configuration
$BEName = "DCVM"
$BEVMConfig = New-AzVMConfig -VMName $BEVMName -VMSize Standard_D1 | `
   Set-AzVMOperatingSystem -Windows -ComputerName $BEVMName -Credential $Cred -ProvisionVMAgent -EnableAutoUpdate | `
   Set-AzVMSourceImage-VM $VirtualMachine -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus "2016-Datacenter" -Version "latest" | `
   Add-AzVMNetworkInterface -Id $backendNic.Id

# Create the DC VM
New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $BEVMConfig

ERROR for First SQL Server VM:

New-AzVM : Parameter set cannot be resolved using the specified named parameters.
At C:\Create_Infra_ps.ps1:131 char:1
+ New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -V ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*    + CategoryInfo          : InvalidArgument: (:) [New-AzVM], ParameterBindingException*
*    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.Azure.Commands.Compute.NewAzureVMCommand*

Set-AzVMSourceImage-VM : The term 'Set-AzVMSourceImage-VM' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path *
was included, verify that the path is correct and try again.
At C:\Create_Infra_ps.ps1:140 char:4
+    Set-AzVMSourceImage-VM $VirtualMachine -PublisherName "MicrosoftWi ...
+    ~~~~~~~~~~~~~~~~~~~~~~
*    + CategoryInfo          : ObjectNotFound: (Set-AzVMSourceImage-VM:String) [], CommandNotFoundException

*    + FullyQualifiedErrorId : CommandNotFoundException*

ERROR for Second VM:

New-AzVM : Cannot validate argument on parameter 'VM'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At C:\Create_Infra_ps.ps1:144 char:72
+ ... ourceGroupName $ResourceGroupName -Location $Location -VM $BEVMConfig
+                                                               ~~~~~~~~~~~

Kenny_I

All replies (3)

Monday, March 11, 2019 7:21 AM âś…Answered | 1 vote

Hi Kenny, 

I did a repro and it works for me. There is a small change in your script that I made. 

$FEVMName = "PBIVM"
$FEVMConfig = New-AzVMConfig -VMName $FEVMName -VMSize Standard_DS11_V2 | `
   Set-AzVMOperatingSystem -Windows -ComputerName $FEVMName -Credential $Cred -ProvisionVMAgent -EnableAutoUpdate | `
   Set-AzVMSourceImage -PublisherName "MicrosoftSQLServer" -Offer "SQL2017-WS2016" -Skus "SQLDEV" -Version "latest" | `
   Add-AzVMNetworkInterface -Id $frontendNic.Id

# Create the SQL Server VM
New-AzVM -ResourceGroupName $ResourceGroupName -Location $Location -VM $FEVMConfig -SubnetName PBISubnet

You just need to remove the -SubnetName switch in "New-AzVM" command. 

Regards,

Msrini


Monday, March 11, 2019 4:55 AM | 1 vote

Hi Kenny, 

The error you have is because -credential without -computername can't exist. 

 Set-AzVMOperatingSystem -Windows -ComputerName $BEVMName -Credential $Cred -ProvisionVMAgent -EnableAutoUpdate -ComputerName YOURCOMPUTERNAME

Reference: https://stackoverflow.com/questions/18144016/powershell-parameter-set-cannot-be-resolved-using-the-specified-named-parameter

Regards, 

Msrini


Monday, March 11, 2019 6:49 AM

I do have -ComputerName defined so it is likely not problem.

Set-AzVMOperatingSystem -Windows -ComputerName $FEVMName

Credentials are defined as following:

## Define a credential object
$SecurePassword = ConvertTo-SecureString 'abc12345678' `
   -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PSCredential ("myadmin", $securePassword)

 

Kenny_I