Share via


New-AzureVM : A parameter cannot be found that matches parameter name

Question

Wednesday, October 9, 2019 10:31 AM

Hi - when trying to create New-AzureVM -ResourceGroupName Prod -Name webserver error is

New-AzureVM : A parameter cannot be found that matches parameter name 'ResourceGroupName'

Switch-AzureMode is deprecated

I tried to install latest AZ Powershell via WebPI however it tells me I have the latest version already installed

Can anyone advise next steps?

Many thanks

Jason

All replies (8)

Wednesday, October 9, 2019 10:51 AM

HI,

Try with New-AzVm

New-AzureVm is part of the old powershell module.  The latest powershell module has Az in it.

Old module is deprecated. Going forward please use the new module.  All documentations will have the commands from latest module.

You can also refer to this document which speaks about creating a windows VM in Azure.

Please use the below command to create a VM

New-AzVm -ResourceGroupName Prod -Name webserver

Please follow this document to remove the old module and install the new module if you are getting a CommandNotFoundException  while using New-AzVm

For the benefit of the community, Please click on "mark as answer" for the replies which helped you to solve the problem.


Wednesday, October 9, 2019 10:55 AM

Hi, 

Are you trying to create a new VM in ARM or classic model?

For ARM use the below command:

    Example 3: Create a VM from a marketplace image without a Public IP
    $VMLocalAdminUser = "LocalAdminUser"
    $VMLocalAdminSecurePassword = ConvertTo-SecureString <password> -AsPlainText -Force
    $LocationName = "westus"
    $ResourceGroupName = "MyResourceGroup"
    $ComputerName = "MyVM"
    $VMName = "MyVM"
    $VMSize = "Standard_DS3"
    
    $NetworkName = "MyNet"
    $NICName = "MyNIC"
    $SubnetName = "MySubnet"
    $SubnetAddressPrefix = "10.0.0.0/24"
    $VnetAddressPrefix = "10.0.0.0/16"
    
    $SingleSubnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix $SubnetAddressPrefix
    $Vnet = New-AzVirtualNetwork -Name $NetworkName -ResourceGroupName $ResourceGroupName -Location $LocationName -AddressPrefix $VnetAddressPrefix -Subnet $SingleSubnet
    $NIC = New-AzNetworkInterface -Name $NICName -ResourceGroupName $ResourceGroupName -Location $LocationName -SubnetId $Vnet.Subnets[0].Id
    
    $Credential = New-Object System.Management.Automation.PSCredential ($VMLocalAdminUser, $VMLocalAdminSecurePassword);
    
    $VirtualMachine = New-AzVMConfig -VMName $VMName -VMSize $VMSize
    $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName $ComputerName -Credential $Credential -ProvisionVMAgent -EnableAutoUpdate
    $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
    $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName 'MicrosoftWindowsServer' -Offer 'WindowsServer' -Skus '2012-R2-Datacenter' -Version latest
    
    New-AzVM -ResourceGroupName $ResourceGroupName -Location $LocationName -VM $VirtualMachine -Verbose

For Classic VM, use the below command:

      Example 1: Create a virtual machine for a Windows configuration  
    PS C:\>New-AzureVMConfig -Name "VirtualMachine07" -InstanceSize ExtraSmall -ImageName (Get-AzureVMImage)[4].ImageName | Add-AzureProvisioningConfig -Windows -Password $adminPassword -AdminUsername PsTestAdmin | New-AzureVM -ServiceName "ContosoService" -AffinityGroup "Contoso" -WaitForBoot
    
    This command creates a provisioning configuration based on a virtual machine configuration for the Windows operating system, and uses it to create a virtual machine in a specified affinity group.
      Example 2: Create a virtual machine for a Linux configuration  
    PS C:\>New-AzureVMConfig -Name "SUSEVM02" -InstanceSize ExtraSmall -ImageName (Get-AzureVMImage)[7].ImageName | Add-AzureProvisioningConfig -Linux -LinuxUser "RootMain" -Password "password" -AdminUsername PsTestAdmin | New-AzureVM
    
    This command creates a provisioning configuration based on a virtual machine configuration for Linux, and uses it to create a virtual machine in a specified affinity group.
      Example 3: Create a virtual machine and add a data disk  
    PS C:\>$Images = Get-AzureVMImage
    PS C:\> $Image = $Images[4]
    PS C:\> $VirtualMachine02 = New-AzureVMConfig -Name "VirtualMachine02" -InstanceSize ExtraSmall -ImageName $myImage.ImageName | Add-AzureProvisioningConfig -Windows -Password "password" | Add-AzureDataDisk -CreateNew -DiskSizeInGB 50 -DiskLabel "DataDisk50" -LUN 0
    
    The first two commands get available images by using the Get-AzureVMImage cmdlet, and stores one of them in the $Image variable.
      Example 4: Create a virtual machine with a reserved IP address  
    PS C:\>New-AzureVMConfig -Name "VirtualMachine06" -InstanceSize ExtraSmall -ImageName (Get-AzureVMImage)[4].ImageName | Add-AzureProvisioningConfig -Windows -Password $adminPassword -AdminUsername "AdminMain" | New-AzureVM -ServiceName "ContosoService02" -AffinityGroup "Contoso" -ReservedIPName $ipName

Regards, 

Msrini


Wednesday, October 9, 2019 12:05 PM

Hi

Many thanks

I can't run that in the PS module it gives me an error - 

WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in t
he same session or used in the same script or runbook. If you are running PowerShell in
 an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all Az
ureRm modules from your machine. If you are running in Azure Automation, take care that
 none of your runbooks import both Az and AzureRM modules. More information can be foun
d here: https://aka.ms/azps-migration-guide.

I tried Uninstall-AzureRm which gave me error - 

WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modu
les cannot be imported in the same session or used in the same script or runbook. If yo
u are running PowerShell in an environment you control you can use the 'Uninstall-Azure
Rm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure
 Automation, take care that none of your runbooks import both Az and AzureRM modules. M
ore information can be found here: https://aka.ms/azps-migration-guide
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in t
he same session or used in the same script or runbook. If you are running PowerShell in
 an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all Az
ureRm modules from your machine. If you are running in Azure Automation, take care that
 none of your runbooks import both Az and AzureRM modules. More information can be foun
d here: https://aka.ms/azps-migration-guide.
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in t
he same session or used in the same script or runbook. If you are running PowerShell in
 an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all Az
ureRm modules from your machine. If you are running in Azure Automation, take care that
 none of your runbooks import both Az and AzureRM modules. More information can be foun
d here: https://aka.ms/azps-migration-guide.

Although I was able to run the New-AzVm command successfully in Azure Cloud Shell

Thanks

Jason


Wednesday, October 9, 2019 12:10 PM

Run Uninstall-AzureRm and once it is deleted, close the PS windows and reopen a new session and install the new module. 

Let me know if you have any further questions. 

Regards, 

Msrini


Wednesday, October 9, 2019 1:57 PM

OK I managed to Uninstall-AzureRM and then ran Install-Module -Name Az -AllowClobber -Scope CurrentUser

I closed existing Powershell ISE session and ran Powershell as Administrator

Thanks

Jason


Wednesday, October 9, 2019 4:01 PM

I am glad that it worked. Can you please mark the proposed response as answered to help other community members. 

Regards, 

Msrini


Thursday, October 17, 2019 12:23 PM

Hi J C M69,

For the benefit of the community, Please click on "mark as answer" for the reply which helped you to solve your problem.


Tuesday, October 22, 2019 12:26 PM

Hello,

Any update on the issue?

If the suggested response helped you resolve your issue, do click on "Mark as Answer" and "Up-Vote" for the answer that helped you for benefit of the community.

Thanks.