I try use function to remove vm from DRS Group
function Remove-DrsVms {
<# .SYNOPSIS
Create a DRS virtual machine group.
.DESCRIPTION
Creates a DRS virtual machine group in the specified
cluster using one, or more, VMs as members.
.EXAMPLE
Create a group with specific VMs
New-DrsVmGroup -Cluster clusterName -VM vm1,vm2 `
-GroupName MyVMGroup
.EXAMPLE
Use the pipeline to specify the cluster for the new DRS group
Get-Cluster clusterName | New-DrsVmGroup -VM vm1,vm2 `
-GroupName MyVMGroup
.PARAMETER Cluster
[System.String]
The name of the cluster to create the group in.
.PARAMETER VMH
[System.String][]
An array of VMs to put into the newly created group.
.PARAMETER GroupName
[System.String]
A name for the new group.
.INPUTS
[VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl]
#>
[CmdletBinding()]
param(
[parameter(
Mandatory=$true,
ValueFromPipelineByPropertyName=$true
)]
[Alias('Name')]
[String]
$Cluster
,
[parameter(Mandatory=$true)]
[String[]]
$VM
,
[parameter(Mandatory=$true)]
[String]
$GroupName
)
$clusterObj = Get-Cluster -Name $Cluster
$clusterSpec = New-Object VMware.Vim.ClusterConfigSpecEx
$vmGroup = New-Object VMware.Vim.ClusterGroupSpec
# add, edit, or remove the VM group
$vmGroup.operation = "remove"
# specify that this is a VM group
$vmGroup.Info = New-Object VMware.Vim.ClusterVmGroup
# give it a name
$vmGroup.Info.Name = $GroupName
# add the VMs to the group
$VM | Foreach-Object {
$vmGroup.Info.VM += (Get-VM $_).id
}
# add the VM group to the cluster specification
$clusterSpec.GroupSpec += $vmGroup
# execute the cluster reconfigure
$clusterObj.ExtensionData.ReconfigureComputeResource(
# provide the specification
$clusterSpec,
# update the cluster config
$true
)
}
Return error
Exception calling "ReconfigureComputeResource" with "2" argument(s): "A specified parameter was not correct: "
+ $clusterObj.ExtensionData.ReconfigureComputeResource(
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException