LucD 1,757 posts since
Oct 31, 2005
Reply
6.
Re: Configure VMs CPUID mask Jul 30, 2008 10:45 AM

in response to:
gss4w
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