Hi,
On all the VMs I create I set the level 1 ecx CPU ID mask to disable SSE4. I'm trying to find out if it is possible to script this configuration using the VI Toolkit, either for existing VMs, or for new VMs. I did not see anything when I searched for information, but I imagine it should be possible.
See
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks, that's what I was looking for.
After I saw your reply to my other message about how use a filter for setting the SCSI controller I tried to see if I could create a filter for setting the CPUID mask:
filter Mask-Extensions { $view = get-view $_.id $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec $featureMask = new-object VMware.Vim.VirtualMachineCpuIdInfoSpec $featureMask.info = new-object VMware.Vim.HostCpuIdInfo $featureMask.info.ecx = "---- ---- ---- 0--- ---- ---- ---- ----" $featureMask.info.level = 1 $vmConfigSpec.CpuFeatureMask = $featureMask $view.ReconfigVM($vmConfigSpec) }
However, when I run this I get an error that says:
Get-View : The argument cannot be null or empty. At D:\Workspace\Create-POD.ps1:50 char:18 + $view = get-view <<<< $_.id You cannot call a method on a null-valued expression. At D:\Workspace\Create-POD.ps1:61 char:18 + $view.ReconfigVM( <<<< $vmConfigSpec)
I don't really understand how filters work, but I'm guessing that the problem is that the system is not done creating the VM before the filter function starts trying to modify its properties. What I'm wondering is if it is possible to set the CPUID mask with a filter at the time a VM is created?
How did you call the filter?
Same as with the SCSI controller filter?
It looks as if there is no object in the pipe ($_ is apparently empty).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, I called the filter the same way I did with the SCSI controller. However, I was trying to apply both filters at the same time, as seen below:
function create-VMs($diskSize,$mem,$vmAcronym) { New-VM -Name ($podFolder.name + "-" + $vmAcronym) ` -Location $podFolder ` -Datastore $podDatastore ` -VMHost $esxhost ` -DiskMB $diskSize ` -MemoryMB $mem ` -GuestID "winNetStandardGuest" ` -NetworkName $podNetworkName ` | set-SCSIController | Mask-Extensions; }
After getting your message, I tested the filter again by itself, and I saw that either one works by itself but not both. Is it possible to apply both filters when I create a VM?
There are 3 problems in that scenario.
1) The New-VM call runs by default in async mode, in other words it comes back immediately, before the new VM is created.
That can be solved by using the -RunAsync parameter.
2) The reason you can't put the filters in sequence is because filter 1 doesn't place the same object it received back in the pipe.
This can be fixed by placing the object in the pipe ($_) back on the pipe.
3) the method used in both filters also runs async.
But since this is a method from the SDK we will have to program a loop ourselves to wait till the method call is finished
Connect-VIServer -Server <VC-server> filter set-SCSIController { $vm = Get-View $_.ID $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.deviceChange = @() $spec.deviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec $spec.deviceChange[0].device = New-Object VMware.Vim.VirtualBusLogicController $spec.deviceChange[0].device.busNumber = 0 $spec.deviceChange[0].device.ControllerKey = 100 $spec.deviceChange[0].device.DeviceInfo = New-Object VMware.Vim.Description $spec.deviceChange[0].device.DeviceInfo.label = "SCSI Controller 0" $spec.deviceChange[0].device.DeviceInfo.summary = "BusLogic" $spec.deviceChange[0].device.hotAddRemove = $true $spec.deviceChange[0].device.key = 1000 $spec.deviceChange[0].device.scsiCtlrUnitNumber = 7 $spec.deviceChange[0].device.sharedBus = "noSharing" $spec.deviceChange[0].operation = "edit" $taskImpl = $vm.ReconfigVM_Task($spec) # Wait for task to finish $task = Get-View $taskImpl while ($task.Info.State -eq "running" -or $task.Info.State -eq "queued"){ $task = Get-View $taskImpl } # Place object back in the pipe $_ } filter Mask-Extensions { $view = get-view $_.id $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec $featureMask = new-object VMware.Vim.VirtualMachineCpuIdInfoSpec $featureMask.info = new-object VMware.Vim.HostCpuIdInfo $featureMask.info.ecx = "---- ---- ---- 0--- ---- ---- ---- ----" $featureMask.info.level = 1 $vmConfigSpec.CpuFeatureMask = $featureMask $view.ReconfigVM($vmConfigSpec) } New-VM -Name <VM-name> -VMHost (Get-VMHost <ESX-hostname>) -GuestId winNetStandardGuest -RunAsync:$FALSE | set-SCSIController | Mask-extensions
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks again for the help, and for explaning why the script needs to be written this way to work.