Automation

 View Only
  • 1.  Erro Function Remove VM - DRS GROUP

    Posted Feb 16, 2016 07:12 PM

    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



  • 2.  RE: Erro Function Remove VM - DRS GROUP

    Posted Feb 17, 2016 10:22 AM

    If you want to remove the DRS VM group I don't think you need to add the VM MoRefs, just the name of the group.

    But why don't you use the Remove-DrsVMGroup cmdlet from our DRSRule module ? No need to reinvent the wheel :smileygrin:

    See DRSRule – a DRS rules and groups module