How to modify a Virtual Machine DRS existing group?

Hello

I use DRS-rules to place virtual machines to a host selected in a Cluster group.

The poblem is that I did not find methods to change (add new virtual machines) to an existing group of DRS 'Virtual Machine '.

As far as I know, the configuration is stored in $ClusterView.ConfigurationEx.Group

Any ideas?

Thank you!

Hi Willibald,

I did some research in the VMware vSphere SDK and made two functions Get-DrsGroup and VmToDrsGroup Add to add one or more virtual machines to a ClusterVmGroup. Some examples of how to use these function exists in the code. If you have added these features to your PowerCLI session, you can use Get-Help to get information about these functions. And also for the examples. For example Get-Help add-VmToDrsGroup-full.

Function Get-DrsGroup {
<#
.SYNOPSIS
Retrieves DRS groups from a cluster.

.DESCRIPTION
Retrieves DRS groups from a cluster.

.PARAMETER Cluster
Specify the cluster for which you want to retrieve the DRS groups

.PARAMETER Name
Specify the name of the DRS group you want to retrieve.

.EXAMPLE
Get-DrsGroup -Cluster $Cluster -Name "VMs DRS Group"
Retrieves the DRS group "Vms DRS Group" from cluster $Cluster.

.EXAMPLE
Get-Cluster | Get-DrsGroup
Retrieves all the DRS groups for all clusters.

.INPUTS
ClusterImpl

.OUTPUTS
ClusterVmGroup
ClusterHostGroup

.COMPONENT
VMware vSphere PowerCLI
#>

  param([parameter(Mandatory=$true, ValueFromPipeline=$true)]$Cluster,
        [string] $Name="*")

  process {
    $Cluster = Get-Cluster -Name $Cluster
    if($Cluster) {
      $Cluster.ExtensionData.ConfigurationEx.Group | `
      Where-Object {$_.Name -like $Name}
    }
  }
}

Function Add-VMToDrsGroup {
<#
.SYNOPSIS
Adds a virtual machine to a cluster VM DRS group.

.DESCRIPTION
Adds a virtual machine to a cluster VM DRS group.

.PARAMETER Cluster
Specify the cluster for which you want to retrieve the DRS groups

.PARAMETER DrsGroup
Specify the DRS group you want to retrieve.

.PARAMETER VM
Specify the virtual machine you want to add to the DRS Group.

.EXAMPLE
Add-VMToDrsGroup -Cluster $Cluster -DrsGroup "VM DRS Group" -VM $VM
Adds virtual machine $VM to the DRS group "VM DRS Group" of cluster $Cluster.

.EXAMPLE
Get-Cluster MyCluster | Get-VM "A*" | Add-VMToDrsGroup -Cluster MyCluster -DrsGroup $DrsGroup
Adds all virtual machines with a name starting with "A" in cluster MyCluster to the DRS group $DrsGroup of cluster MyCluster.

.INPUTS
VirtualMachineImpl

.OUTPUTS
Task

.COMPONENT
VMware vSphere PowerCLI
#>

  param([parameter(Mandatory=$true)] $Cluster,
        [parameter(Mandatory=$true)] $DrsGroup,
        [parameter(Mandatory=$true, ValueFromPipeline=$true)] $VM)

  begin {
    $Cluster = Get-Cluster -Name $Cluster
  }

  process {
    if ($Cluster) {
      if ($DrsGroup.GetType().Name -eq "string") {
        $DrsGroupName = $DrsGroup
        $DrsGroup = Get-DrsGroup -Cluster $Cluster -Name $DrsGroup
      }
      if (-not $DrsGroup) {
        Write-Error "The DrsGroup $DrsGroupName was not found on cluster $($Cluster.name)."
      }
      else {
        if ($DrsGroup.GetType().Name -ne "ClusterVmGroup") {
          Write-Error "The DrsGroup $DrsGroupName on cluster $($Cluster.Name) doesn't have the required type ClusterVmGroup."
        }
        else {
          $VM = $Cluster | Get-VM -Name $VM
          If ($VM) {
            $spec = New-Object VMware.Vim.ClusterConfigSpecEx
            $spec.groupSpec = New-Object VMware.Vim.ClusterGroupSpec[] (1)
            $spec.groupSpec[0] = New-Object VMware.Vim.ClusterGroupSpec
            $spec.groupSpec[0].operation = "edit"
            $spec.groupSpec[0].info = $DrsGroup
            $spec.groupSpec[0].info.vm += $VM.ExtensionData.MoRef

            $Cluster.ExtensionData.ReconfigureComputeResource_Task($spec, $true)
          }
        }
      }
    }
  }
}

Best regards, Robert

I changed the error handling logic in the Add-VMToDrsGroup function.

Post edited by: RvdNieuwendijk

Tags: VMware

Similar Questions

  • How to access the virtual machines to different physical network?

    Hello

    I'm new to ESXi, can someone tell me how can I access virtual machines on the physical network existing in case I use different IP classes? Physics of the network by using the class C IPs and I assigned IPs to virtual machines of class A? If it is possible, then, what are the steps?

    In fact, I installed exchange 2010 VMs and also want to access the email accounts of physical network.

    Thank you.

    vmjunki wrote:

    You mean there's no way in ESXi to configure the way so we can access the virtual machines to physical network? without third-party applications.

    Because it is impossible for the various networks IP connect without a router, you must have such a device. There is really no difference in that in a pure virtual or physical environment.

    You might think the ESXi host as a box with one or more servers (virtual) inside and one or more layer (virtual) two switches, just like a small server room. This means you will need to provide the same type of connectivity that you would have to a new server room with machines configured with addresses in a different IP network range.

  • How to move the virtual machine from one cluster to another cluster

    How to move the virtual machine from one cluster to another cluster

    If two Clusters are in the same data center, you could do a 'live' migration or vMotion, if that's the case.   If the virtual machine is turned off, it may be migrated regardless of the data center.

  • Retrieve a list of virtual machine is in a group of virtual machine DRS

    Hello

    I want to retrieve a list of virtual machines in a virtual machine DRS group. I found the following oneliner, but the result is empty. I used Powercli 5.5 release 1 and vSphere 5.5 update1

    (Get-Cluster CLUSTER). ExtensionData.ConfigurationEx.Group |? {$_.vm} | % {' GROUP ${$_.name} found in this cluster "; foreach ($CurrentVM to $_.vm) {(Get-view-id $CurrentVm) .name}}

    Need help

    No problem, we add an additional condition to the Where clause

    $clusterName = "MyCluster"$vmGroupName = "VMgroup"
    
    (Get-Cluster -Name $clusterName).ExtensionData.ConfigurationEx.Group |Where {$_ -is [VMware.Vim.ClusterVmGroup] -and $_.Name -eq $vmGroupName} | %{  Get-View $_.VM | Select @{N="VMgroupVM";E={$_.Name}}}
    
  • How to keep a virtual machine on a different host to another load balancing virtual computer

    I have two virtual computers (servers) that I use for the application load balancing and I don't want nor server/VM to finish on the same host at any time.   Balancing of the DRS is used in our vSphere environment.  What is the best way to implement?

    Yes that's what I was talking about-

    You can control the placement of virtual machines on the hosts in a cluster using Affinity rules.

    You can create two types of rules.

    VM HOST affinity - specify affinity or anti-affinite between a group of VMS and a group of guests. An affinity rule specifies that the members of a selected group virtual machine DRS may or must be running on a specific host DRS group. An anti-home rule specifies that the members of a selected group virtual machine DRS cannot run on a specific host of the DRS group members.

    Affinity of machine VM-virtual - specify affinity or an anti-affinite between each of the virtual machines. A rule specifying the affinity causes DRS to try to keep the specified virtual machines together on the same host, for example, for performance reasons. With a rule anti-xxx, DRS tries to keep the specified virtual machines, for example, so that when a problem arises with a host, you do not lose the two virtual machines.

    Agic, the Guide to management resources - http://pubs.vmware.com/vsphere-50/topic/com.vmware.ICbase/PDF/vsphere-esxi-vcenter-server-50-resource-management-guide.pdf Page 75 for more information-

  • VShield Configuration Manager 4.1 (and how to protect a virtual machine?)

    I have 2 ESXi hosts currently configured in vCenter 4.1.  Before vShield installation Manager, he had 3 vSwitches present on each server; a regular and two distributed.

    • vSwitch0 - connected to vmnic0 - has management and production of network 1 10.168.90.x

    • VLAN 10.1 - VMFN connected to vmnic1 on each host - connects to the private physical network 10.1.x.x

    • VLAN 10.2 - VMFN connected to vmnic2 on each host - connects to the private physical network 10.2.x.x

    After you install vShield Manager in a new virtual machine and then to deploy vShield Zones to each ESXi host, develops a new vSwitch

    vmservice-vswitch - again group of ports in Virtual Machine vmservice-vshield-pg - not connected to any physical cards

    VMS individual vShield-FW created for each host have connected network cards as below

    • Production network normal 1 - VM Network adapter (attached to vSwitch 0).

    • Production network normal 2 - VM Network adapter (attached to vSwitch 0).

    • Adapter 3 - vmservice-vshield-pg network

    I tried to connect my VMs to the network vmservice-vshield-pg in order

    to protect them and place them behiind the firewall.  However, who has

    seem to work, and my VM has lost network connectivity.

    How to protect a virtual machine that needs to connect to the normal production

    Network (on vSwitch0)?  Is there any configuration steps I'm missing?

    What happens if I want to connect a virtual machine or one of its network cards to one of the 10.1.xx

    or 10.2.x.x networks rather than the normal 10.168.90.x network?  What

    additional steps should I make?  The new 4.1 documentation is not

    helped at all, and it seems that the old vShield Zones 1.0 docs are not

    applies to all.

    There is no need to change the virtual computer is connected to the network.

    Just activate/install vShield zones on your hosts and add rules to the vSwitch or data center.

    The virtual machine will be becomes protected if no error is displayed.

  • How to move a virtual machine from one virtual switch to the other since the SDK / command line?

    How to move a virtual machine from one virtual switch to the other since the SDK / command line?

    Joshua Smith

    Are you referring to the evolution of the virtual machines network portgroup of one to the other and in your case potentially issue on to another vSwitch? If so, take a look at this script: updateVMPortgroup.pl everything you do really makes a call to ReconfigVM_Task() and passing in a specification change and put to day the network in which you want to change

    =========================================================================

    William Lam

    VMware vExpert 2009

    Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

    repository scripts vGhetto

    VMware Code Central - Scripts/code samples for developers and administrators

    150 VMware developer

    Introduction to the vMA (tips/tricks)

    Getting started with vSphere SDK for Perl

    Twitter: @lamw

    If you find this information useful, please give points to "correct" or "useful".

  • How to make the virtual machine in 64-bit with VMware6.5

    My CPU: AMD Turion 64 * 2

    Operating system: Windows xp 32

    Question:

    I want to run Open solaris 2008 which is 64 bit, I did a virtual machine but it is 32-bit. You tell me how to make the virtual machine in 64 bits in VMware6.5, I really appreciate.

    Yes.  Power off the virtual computer.  Change the settings.  Change the guest OS to Solaris 10 to Solaris 10 64-bit.

  • vCenter log files entries for the new virtual machine or distributed groups of ports

    All,

    I can't find the entries for the new virtual machine or distributed groups of ports in the vpxd.log file.

    Any suggestions?

    Thank you

    This kind of info are in the DB vCenter.

    Not in the logfile (used for debugging purposes).

  • How to create the new virtual machine vm existing in the data store on ESXI

    I have ESXi and couple of virtual machines.

    I have the vsphere client on Windows 7.

    I then deploy the ovf from the vsphere client vm and it began to import my VM 30 GB.

    In the morning, I realized my vm with a vmdk file file has been transferred in the data store

    But I couldn't see any virtual computer.

    Now I don't know how to turn on this vmdk file that is in my data store

    @King_Robert

    It's a very bad habit of yours to just copy and paste content created by someone else, without even mentioning the source (http://www.mustbegeek.com/create-copy-of-existing-virtual-machine-in-esxi-server/)

    André

  • How to create the virtual machine to a virtual machine existed file?

    I have two hard drives on my VMware host. There are virtual machines on a SATA drive, how do I list these files of virtual machines and copy one of them to create a new virtual machine (it can save a lot of my time!). I did this way on VMware server 2.0 because I can see what they were and where they were under Windows. But on vSphere, how can I do? Maybe you guys have other ways to do it?

    Thank you!

    George

    On vSphere, I suggest you use autonomous vConventer instead. It is quite simple and easy to use. Alternatively, you can copy or clone the virtual disk to the virtual machine via the Console (ESX) Service offline

    vcbMC - 1.0.6 Beta

    Lite vcbMC - 1.0.7

    http://www.no-x.org

  • How to activate Java Virtual Machine (JVM)? I updated yesterday and somehow, he found himself distraught.

    I've upgraded to the latest version yesterday and when I went to a website of the Government today, it tells me that I have no access until I have activate the Virtual Machine (JVM) Java. How can I do this? (I access this site using Internet Explorer - but I prefer Firefox)

    If you upgraded from a version of Firefox before Firefox 3.6, the Java version you have installed is not recognized. Firefox 3.6 and later versions require Java 1.6.0.10 or higher; you have Java 1.6.0.05

    Other topics: ~ ~ Red: you have installed the plug-ins with known security issues. You must update them immediately. ~ ~

    Java Update: your 1.6.0 ~ ~ red:05 ~ ~ worm. ; current version 1.6.0.20 (important update 15/04/2010)
    (~ ~ Red: Firefox 3.6 and above all requires Java 1.6.0.10 or higher ~ ~; see: http://support.mozilla.com/en-US/kb/Java-related+issues#Java_does_not_work_in_Firefox_3_6 )
    (Windows users: do the update manually, very easy.)
    ~ ~ Red: check your version here ~ ~: http://www.mozilla.com/en-US/plugincheck/
    See: Java Update
    Do the update with Firefox closed.
    NOTE: Java version 1.6.0.21 was released. It is mainly an update for developers of Java applications and most of the users don't need to worry about downloading version 1.6.0.21. Right now, the option of update in existing Java 1.6.0.20 facilities are not updated to version 1.6.0.21. right now, it must be manually downloaded and installed. According to the release notes for Java:
    "Bug fixes ".
    Java SE 6 Update 21 contains no additional patches for vulnerabilities to its previous version, Java SE 6 Update 20. Java SE 6 Update 20 users have the latest security patches and don't have no need to upgrade to this version is current on security patches. " Source: http://java.sun.com/javase/6/webnotes/6u21.html

  • How to start a virtual machine without vmx file

    Hello, I have a virtual machine that I want to start up using 10.0.0 on Ubuntu 14.04 32-bit workstation but I don't have multiple vmdk files and a file on me vmxf and apparently, that's all that is in the software. How do I run something like that?

    Hello
    You cannot start a virtual machine without a vmx file.
    If you do not have a vmx file - fly a.
    For example this one:
    -----------------------------------

    . Encoding = "windows-1252".

    config.version = '8 '.

    virtualHW.version = '8 '.

    scsi0. Present = 'TRUE '.

    scsi0.virtualDev = "free".

    memsize = "2048".

    scsi0:0. Present = 'false '.

    scsi0:0. FileName = "set-path-to-bootdisk-and-then-set-.present-to-true-to-activate".

    ethernet0. Present = 'TRUE '.

    ethernet0.virtualDev = "e1000".

    displayName = "minimal-vm.

    guestOS = "windows7-64.

    virtualHW.productCompatibility = "hosted".

    ------------------------------------

    That cuts into a file and store it as a *.vmx.
    Then launch the new VM with
    VMware /path-to-vmx/name.vmx or
    vmplayer /path-to-vmx/name.vmx
    Other users may also recommend to simply launch the user interface and follow the file > New menu...
    and then order the new virtual machine to the card by selecting your existing virtual disks.

  • PowerShell - how to convert a virtual machine model

    Now that the copy of a model works, I would like to convert this model in VM.

    with the powershell command, I use.

    Thank you for help

    As RyanMcL , using the Get-View methods and API will go faster, especially if you have more models to convert to virtual machines.

    But since denjoh44 is eager to convert an existing in VM model, you don't want to use the MarkAsVirtualMachine() of an object VirtualMachine (not the MarkAsTemplate() method).  It's a little more complicated, because the method requires a ResourcePool MoRef in which place the machine virtual result.

    And if you have really been focused on speed, you probably want to use the - Property parameter on the Get-View call, to only return the minimum number of properties.  This maximizes the speed and minimizes the use of memory (avoiding an OutOfMemoryException).

    Another thing to keep in mind is how you use the - Filter parameter on the call in the opinion of the GET.  The value you specify it is used as a regular expression pattern.  So, by using something like @{"Name" = 'vmname1'} must return the view object for the machine named "vmname1", but also returns "vmname10", "vmname1314", "vmname1other", etc.

    So, it would be preferable to specify anchor characters only happen exactly the machine you want, like @{"Name" = "^ vmname1$"}.

    Collect these things would result in something like:

    ## get the View obj of the Resource Pool into which to place the VirtualMachine#    (put your own cluster name in this line)$viewMyResPool = Get-View -ViewType ResourcePool -Property Name -SearchRoot (Get-View -ViewType ClusterComputeResource -Property Name -Filter @{"Name" = "^myCluster$"}).MoRef
    
    ## get the View obj of the given template (put your own template name in this line)$viewTemplate = Get-View -ViewType VirtualMachine -Property Name -Filter @{"Name" = "^myTemplate$"}## convert the template to a VM, in the given ResourcePool$viewTemplate.MarkAsVirtualMachine($viewMyResPool.MoRef, $null)
    

    So, a little more upfront work to write it, but if you have a large number of models to convert VM, it is probably worth the time.

  • How to move a virtual machine to another store of data on the same host

    Hello

    I have a single ESX4 host with 3 data warehouses and I need to move a virtual machine to another data store, how can I do that since I don't have the ability to migrate the virtual machine when I am connected directly to the client with vSphere host and I do not have a server vCenter also?

    Thanks, Julien

    Hello

    Yes, you can use #vmkfstools-i /vmfs/volumes/datastore/VM/VM.vmdk /vmfs/volumes/datastore/VM1/VM1.vmdk

    For the record, the data store must be shared if you copy of VM and VM must be turned off. In the above command you copy VM.vmdk to VM1.vmdk and add the newly created with this existing VMDK VM.

    If you have found this or other useful information, please consider awarding points to 'Correct' or 'useful '.

Maybe you are looking for

  • connection Internet HP 7 1800

    My 7 1800 hp Tablet does not connect to the internet. It says wireless home is saved, but there is no signal on the top bar, and connection will not work. Does anyone else have this problem?

  • Questions about upgrading a Compaq Presario CQ5205Y desktop computer system

    Good evening I'm about to embark on my first serious upgrade of my computer, and I thought it would be a good idea to arrive before I get too far down the rabbit hole (and knocked out my Internet access).  What motivates the need to upgrade, it's tha

  • run the command runtimemenu for example APP_SC_EMPTY_ARRAY and other programmatic

    Dear community I have a simple question of relaively. There are a lot of labview build in commands in the APP_SC_... section for different actions. I want to run some of these commands, using a key instead of the menu DURATION event event. As all of

  • CVI crashes when compiling with VISA

    LabWindows/CVI does not compile when I try to use VISA: For a very simple program (only the user interface, no communication instrument multithreading, either), when I include "visa.h", it does not compile and crashes from time to time: -When I hit '

  • Error code: 0x8007371B "ERROR_SXS_TRANSACTION_CLOSURE_INCOMPLETED".

    Running Windows 7 Pro 64 bit.  Have done all the suggested fixes and no change. First error = one or more required members of the transaction are not present. Clicking Details gets = error: ERROR_SXS_TRANSACTION_CLOSURE_INCOMPLETED (0x8007371b) Ran s