VMware Cloud Community
the3rdd
Contributor
Contributor
Jump to solution

New-VM Issue

Alright so I have a script I need a little help with. Script purpose, parse out a section of a name, check to see if a vm with that name is created, then create the vm with the parameters if it is already not created. The problem is I get an error of

"New-VM: Parameter set cannot be resolved using the specified named parameters." and was wondering if anyone had any ideas.

The code is as follows

Get-Datacenter | where {$Name -notmatch 'nottest*'} | foreach {
    $DC = $_   
    $DC | Get-VMHost | %{

        foreach ($DC.Name in $DC)
        {
            $NewName = $DC.Name
            $Site = $NewName.substring(0,6)

            $SiteTest = $Site + "test01"          
            Write "DataCenter: $Site"           
           
 
   
    if (!(Get-VM $SiteTest -ErrorAction SilentlyContinue)) {
       New-VM -Description "New Test Server" -Template TestTemplate -OSCustomizationSpec TestCustomization -VMhost (Get-Cluster ($Site + "Test_Center") | Get-VMHost | Select-Object -First 1) -Name ($Site + "TestVM01") -DiskStorageFormat Thick -Version v7 -ResourcePool ($Site + "_TestVM") -DiskMB 40960 -NumCPU 1 -MemoryMB 2048 -GuestID windows7Server64Guest -Datastore ($Site + "_TestStore")
       Write "Creating Test Server $SiteTest"
     
      }
      }
      }
      }
    

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

When you use the Template parameter you can't use the DiskMB, NumCpu, MemoryMB, GuestId and Version parameters.

You can use the script from my PowerCLI cmdlet XRef – Another look post to see which parameter belongs to which parameterset. No need to start puzzling.

New-VM-pset.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

If you execute the PowerCLI command "Get-Help New-VM" you will see four different parameter sets below the SYNTAX tag. All your parameters have to come from one set. You can't mix them. And you have to use at least one parameter that makes the parameter set unique. So you will have to solve a little puzzle. Smiley Wink

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
LucD
Leadership
Leadership
Jump to solution

When you use the Template parameter you can't use the DiskMB, NumCpu, MemoryMB, GuestId and Version parameters.

You can use the script from my PowerCLI cmdlet XRef – Another look post to see which parameter belongs to which parameterset. No need to start puzzling.

New-VM-pset.png


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
the3rdd
Contributor
Contributor
Jump to solution

Awesome. I will then call set-vm. I appreciate it.

0 Kudos