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"
}
}
}
}
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Regards, Robert
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome. I will then call set-vm. I appreciate it.