That is one of the drawbacks of using Code Capture.
You really need to consult the API Reference to know what the captured code is actually doing/calling.
In this case the ReconfigureComputeResource method is called to make the changes you did in the Web Client.
From the description of the method you'll see that the 2nd parameter is the modify parameter.
From the description: "Flag to specify whether the specification ("spec") should be applied incrementally. If "modify" is false and the operation succeeds, then the configuration of the cluster matches the specification exactly; in this case any unset portions of the specification will result in unset or default portions of the configuration."
The $_.this notation is to indicate that the method is called on the object, a cluster.
But in this case the vSphere object for a cluster.
This is not the same object as the .NET object for a cluster, which is returned by Get-Cluster.
There are 2 ways to go from the .NET object to the vSphere object.
- via the ExtensionData property
- via the Get-View cmdlet
One point to understand, the PowerCli framework offers 2 ways for all API methods.
One with the _Task suffix, where the call will return immediately and the task will run in the background.
The call without the _Task suffix, where the call will come back when the task is completed.
Something like the RunAsync switch on PowerCli cmdlets.
Your code would be something like this
$vms=Get-VM-Name <name>-Location $cluster
ForEach($vmin$vms){
$spec=New-Object WMware.Vim.ClusterConfigSpecEx
$spec.dasVmConfigSpec=New-Object VMware.Vim.ClusterDasVmConfigSpec[](1)
$spec.dasVmConfigSpec[0]=New-Object VMware.Vim.ClusterDasVmConfigSpec
$spec.dasVmConfigSpec[0].operation ="add"
$spec.dasVmConfigSpec[0].info =New-Object VMware.Vim.ClusterDasVmConfigInfo
$spec.dasVmConfigSpec[0].info.key =New-Object VMware.Vim.ManagedObjectReference
$spec.dasVmConfigSpec[0].info.key.type ="VirtualMachine"
$spec.dasVmConfigSpec[0].info.key.value =$vm.ExtensionData.MoRef.Value
$spec.dasVmConfigSpec[0].info.RestartPriority ="medium"
$spec.dasVmConfigSpec[0].info.PowerOffOnIsolation =$True
$spec.dasVmConfigSpec[0].info.dasSettings =New-Object VMware.Vim.ClusterDasVmSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmToolsMonitoringSettings =New-Object VMware.Vim.ClusterVmToolsMonitoringSettings
$spec.dasVmConfigSpec[0].info.dasSettings.vmComponentProtectionSettings =New-Object VMware.Vim.ClusterVmComponentProtectionSettings
}
$cluster.ExtensionData.ReconfigureComputeResource_Task($spec,$true)