Deploy multiple virtual machines on several hosts evenly?

Hello people!

I wrote a small script to deploy many virtual machines on several hosts at random.

But I would rather deploy a virtual machine to each host in a table and then start over again until the number of virtual machines to deploy exhausted.  Distribution of the burden of deployment as evenly as possible.

Anyone have a suggestion?  Example of nested loops?

PowerShell beginner, here.

Thank you

romatlo

One way to do this is with the modulo operator (%), something like this

$numVMs = 11

$tgtEsx = get-Cluster "Westcreek | Get-VMHost-name z420 *.

1.. $numVMs | %{

[New-VM-name 'Test $($_)' $tgtEsx[$_%$tgtEsx.Count - VMHost]

}

Tags: VMware

Similar Questions

  • Deploy multiple virtual machines simultaneously

    Hello

    I'm trying to deploy multiple virtual machines at the same time using powercli.  I think I have has the switch - RunAsynch, howerver, this doesn't seem to work, instead of that virtual machines are deployed one at a time.  Here is my code:

    SE connect-VIServer-Server vc1. MYDOMAIN.local - user MYDOMAIN\MYACCOUNT-password MYPASSWORD

    New-vm - vmhost prodh1. MYDOMAIN.local - name of TEST - SVR01 - model W2K8R2SP1 - IOMEGA data store - OSCustomizationspec-W2K8R2SP1-_Tobedeleted location | Start-VM - RunAsync

    New-vm - vmhost prodh1. MYDOMAIN.local - name of TEST - SVR02 - W2K8R2SP1 - IOMEGA data store model - OSCustomizationspec-W2K8R2SP1-_Tobedeleted location | Start-VM - RunAsync

    New-vm - vmhost prodh1. MYDOMAIN.local - name of TEST - SVR03 - W2K8R2SP1 - IOMEGA data store model - OSCustomizationspec-W2K8R2SP1-_Tobedeleted location | Start-VM - RunAsync

    New-vm - vmhost prodh1. MYDOMAIN.local - name of TEST - SVR04 - W2K8R2SP1 - IOMEGA data store model - OSCustomizationspec-W2K8R2SP1-_Tobedeleted location | Start-VM - RunAsync

    Start-Sleep - seconds 300

    Get - vm "TEST-SVR01 | Get-VMGuestNetworkInterface Guestuser - administrator - GuestPassword "MYPASSWORD" |? {$_.name - eq "Connect to network Local 3"} | Game-vmguestnetworkinterface administrator - Guestuser - GuestPassword "MYPASSWORD" - IPPolicy - 192.168.1.25 static IP - Netmask 255.255.255.0 - Gateway 192.168.1.1 DNS - 192.168.1.2,192.168.1.3 - RunAsync

    Get - vm "TEST-SVR02 | Get-VMGuestNetworkInterface Guestuser - administrator - GuestPassword "MYPASSWORD" |? {$_.name - eq "Connect to network Local 3"} | Game-vmguestnetworkinterface administrator - Guestuser - GuestPassword "MYPASSWORD" - IPPolicy - 192.168.1.25 static IP - Netmask 255.255.255.0 - Gateway 192.168.1.1 DNS - 192.168.1.2,192.168.1.3 - RunAsync

    Get - vm "TEST-SVR03 | Get-VMGuestNetworkInterface Guestuser - administrator - GuestPassword "MYPASSWORD" |? {$_.name - eq "Connect to network Local 3"} | Game-vmguestnetworkinterface administrator - Guestuser - GuestPassword "MYPASSWORD" - IPPolicy - 192.168.1.25 static IP - Netmask 255.255.255.0 - Gateway 192.168.1.1 DNS - 192.168.1.2,192.168.1.3 - RunAsync

    Get - vm "TEST-SVR04 | Get-VMGuestNetworkInterface Guestuser - administrator - GuestPassword "MYPASSWORD" |? {$_.name - eq "Connect to network Local 3"} | Game-vmguestnetworkinterface administrator - Guestuser - GuestPassword "MYPASSWORD" - IPPolicy - 192.168.1.25 static IP - Netmask 255.255.255.0 - Gateway 192.168.1.1 DNS - 192.168.1.2,192.168.1.3 - RunAsync

    Get-NetworkAdapter "TEST-SVR01 | Together-NetworkAdapter - NetworkName VM1-confirm: $false

    Get-NetworkAdapter "TEST-SVR02 | Together-NetworkAdapter - NetworkName VM1-confirm: $false

    Get-NetworkAdapter "TEST-SVR03 | Together-NetworkAdapter - NetworkName VM1-confirm: $false

    Get-NetworkAdapter "TEST-SVR04 | Together-NetworkAdapter - NetworkName VM1-confirm: $false

    If anyone can help?

    Thank you

    Duncan.

    Yes, you are right.

    By specifying the param -VM (Get - VM $modelVM) , you create the new virtual machine from an existing one.

    Just change the cmdlet New - VM settings according to your needs and let the VM - far.

    It creates your virtual machines based on a template and specification of customization.

    $esxName = "prodh1.MYDOMAIN.local"
    $template = "W2K8R2SP1"
    $datastore = "IOMEGA"
    $newVmList = "TEST-SRV01", "TEST-SRV02", "TEST-SRV03", "TEST-SRV04"
    $custSpec = "W2K8R2SP1"
    $location = "_Tobedeleted"
    $taskTab = @{}
    
    # Create all the VMs specified in $newVmList
    foreach($Name in $newVmList) {
         $taskTab[(New-VM -Name $Name -VMHost (Get-VMHost -Name $esxName) -Template $template -Datastore $datastore -OSCustomizationSpec $custSpec -Location $location -RunAsync).Id] = $Name
    }
    

    Of course, you can write it as before. You will need to only change the $newVmList variable in the original script.

    foreach($Name in $newVmList) {
         $taskTab[(New-VM -Name $Name -VMHost "prodh1.MYDOMAIN.local" -Template" W2K8R2SP1" -Datastore" IOMEGA" -OSCustomizationSpec "W2K8R2SP1" -Location "_Tobedeleted" -RunAsync).Id] = $Name
    }
    

    You will also need to insert the remaining part with the while loop and the customizations in your network!

    http://www.lucd.info/2010/02/21/about-async-tasks-the-get-task-cmdlet-and-a-hash-table/

    Concerning

    Emanuel

  • deploy multiple virtual machines using vmdk and SID file

    Hello

    Need to know if I am correct or miss me something... I deploy many virtual machines using method.

    1. remove the vmdk files a XP.

    2. create new folders and copy the vmdk into this folder.

    3. create virtual machines using existing vmdk files.

    4 rename the computer and join it to the domain.

    My question is, my VMDK files are an existing xp VM (no longer exist), what is the status of the deployed virtual machines? they still have the same SID or it is changed? I managed to join to the domain, but do not want surprises in the future.

    Note:

    I had another option, could have all these automated with new SID using PowerCLi, unfortunately, osCustomization has default, I can't event run the get-OsCustomization command, it keeps failing.

    Thank you.

    Yes, Windows writes the SID on disk (virtual disk for virtual machines) or physical disk for physical machines.  The guest operating system has no idea on the vmx file.

    Dave

    VMware communities user moderator

    Now available - vSphere Quick Start Guide

    You have a system or a PCI with VMDirectPath?  Submit your specifications to Officieux VMDirectPath HCL.

  • Deploy multiple virtual machines from one model to the help of customization of the OS and a text file for hostname and IP

    Hi all

    Not sure if this has already been answered, I did a search on the forums, but couldn't find an answer to what I'm looking for.

    I want to fully automate the deployment of multiple VMs of a model using a customization file, but also to retrieve the host names and IP addresses from a text file / spreadsheet.

    for example:

    I need to deploy a test environment of 30 virtual machines using the template file and customizing TestVM. I have a spreadsheet with the VM host names and IP addresses. The process now is to manually enter the host name and IP when the customization file invites to do while deploying them in each virtual machine. The customization file takes care of the rest (license key, admin password, add to the domain etc.) can I automate entry of the name of host and IP addresses in reading from a text file?

    Thanks in advance!

    Take a look on the deployment, customization and modification of virtual machines to a csv file

    There are many more examples of this community on the same subject,

  • Unable to choose the host when you deploy a virtual machine template

    Good Morning-

    I feel that the answer to this is with myself; However, I would ask - I try to deploy a virtual machine model for test purposes and I want the virtual machine must be created on a specific host.  When I start the Wizard "deploy the virtual machine of model", I am only able to select the cluster and not a specific host.   Is it possible for me to be able to select the host to which the virtual machine will be deployed without disabling DRS?

    Thank you very much in advance for the help.

    Steve

    What happens if you right click on the host that you want to deploy on the virtual machine to and select deploy from model - but don't forget if you have a DRS activated with anything other that Manuel DRS will select the host on which the virtual machine starts on and it would not be that you deply to--

    If you find this or any other answer useful please consider awarding points marking the answer correct or useful

  • Stop several hosts and the virtual machine on the host computers

    Sorry to bother the community again. Right now I have a script that stop or suspend virtual machines on a host in order using an external file to store the order (with the help of lamw). The plan is for the script to reside in a virtual centre with multiple hosts. The script must be able to stop the vm on the host, the closure of the host (to be ordered the same idea with the external file), then jump to the next host and continue the same process. I tried to create nested for loops this task, but it doesn't seem to work. Any help would be appreciated. I have attached the script. Thanks in advance

    I think you try to only syspend or stop each VM and then stop the host.

    This code might help.

  • How one move the templates of virtual machine from one host to another host in the cluster even

    Hello

    Can you get it someone please let me know how to move the templates of virtual machine from one host to another host in the cluster even?

    Thank you

    James

    Welcome to the forums!

    Convert it to a virtual machine (right click on guest and choose the appropriateoption), move it through the migration feature (right-click Guest, and then choose "Migrate") and convert into a model (right click on guest again and choose to convert to a template).

    If you found this information useful, please consider awarding points to 'Correct' or 'Useful' responses Thank you!!

    AWo

    VCP / vEXPERT 2009

  • No network connection between the virtual machines on different hosts ESXi

    I have several 5.0 ESXi hosts in a cluster managed by vCenter Server 5 and I have network problems:

    1. [Host A] running a virtual machine can ping any other computer virtual running on the [host A] great!
    2. A virtual machine running on host [B] can ping any other virtual machine running on [B] home - very well!
    3. [host A] (from the ESXi console) can ping any virtual machine running on [B] home - even better!
    4. [B] home (from the ESXi console) can ping any virtual machine running [host A] - beautiful set!
    5. A virtual machine running [host A] can not ping any virtual computer running on host [B] and vice versa - bad, very bad!

    So basically the problem is that the virtual machines can communicate on hosts. It is a major problem that I need to fix, for obvious reasons.

    Networking on all hosts is configured exactly the same way: a unique and standard vSwitch with a pair of gigabit network cards grouped, vmkernels configured for the vMotion, NFS and network management and a group of ports configured for the VIRTUAL local area network used by the VMs. (vMotion works fine on hosts, storage vMotion works very well too.) All virtual machines are servers Windows (2003 and 2008).

    Reason #3 and #4 above, my assumption is that #5 must be the result of an ESXi/vCenter configuration issue and not a problem with the switches of material upstream. Is this a reasonable assumption?

    Whatever it is, can anyone offer suggestions on how can I fix? It is quite annoying as I'm pretty sure that these hosts are configured in the same manner as those of our production cluster, which does not at all these problems!

    Thanks in advance for any help you guys can provide.

    To be honest, it looks like a problem with your physical network-

    How is the physical network configured - are NIC connects it to the same physical switches? Are the virtual machines on the same subnet? If this is not the case, they are able to ping the gateway sbnet? Can you piing host IP address from the virtual machines?

    I also moved it to a forum more approiate.

  • Single VMDK for multiple virtual machines in esx3.5?

    Hello

    Is it possible to use a single VMDK to host several VM in ESX3.5 or is this feature on the way?  I think the vmware view tech that allows you to host multiple virtual machines to a single image and store only the deltas for VMS replca.

    We organize several ts who are about 12 GB per image, and each server is essentially the same.  It would reduce the space if these could be consolidated at the level of vmware.

    Thank you very much.

    What you are referring to the notion of linked Clones, it's something completely different to share a single VMDK.  with linked clones, you actually run mulitple copies of a single Machine.  This fuinctionality is not available in ESX Raw but is a characteristic of Lab Manager and VMware View Premium.

    If you have found this device or any other answer useful please consider useful or correct buttons using attribute points

    Tom Howarth

    VMware communities user moderator

    Blog: www.planetvm.net

  • Is it Possible to access only bypassed FC HBA to multiple virtual machines

    Hello

    I have a FC HBA on my 5.5 ESX. Server. It does not support the function of SR - IOV. Is it possible to access this FC HBA across multiple virtual machines?

    If possible, please provide as follows to go further.

    Kind regards

    Aashish

    It is not possible. The basic material underlying PCI specification does not have a single shared between several independent operating systems PCI device.

    SR - IOV solves by creating the virtual function peripheral PCI, but as you mentioned, that he can't stand not and first of all, ESXi supports that SR - IOV for Ethernet network devices and not for native FC HBA (excluded FCoE) functions.

  • GUI: how to run the same command on multiple virtual machines at the same time?

    Hello

    Suppose we have several operations on multiple virtual machines (for example as updated virtual hardware, install vmtools - but it could be something else of course...).

    I would avoid clicking on each virtual machine (especially when we have hundreds of different groups).  It is possible to select sort

    (they are not side by side) and perform on a particular operation on all selected both?

    Hello

    If you use vCenter 5.1 + you can also try to use marking and assign tags on the items in the inventory.

    VSphere 5.5 Documentation Center - apply a label to an object

    Search for items by this tag.

    If you want to use PowerCLI 5.5, you can also search the inventory by this tag.

    Get-VM-Tag which lists all the virtual machines with which

    Here are some links for getting started with vSphere PowerCLI

    Back to Basics: part 1 - installation PowerCLI | VMware PowerCLI Blog - Articles from VMware

    vSphere PowerCLI Documentation

  • Help for a demo: create multiple virtual machines

    Hello

    I am a beginner in vCO, I completed the installation and configuration with success and I started to create workflows, but I guess that I need help with an example that I started yesterday:

    I am creating several virtual machines at the same time, I mean all the user have to do is say how VMs, he wants to be created and the workflow must do the rest, but I don't know what is the best way to do so, in the present workflow in the library , find us only 'create simple VM' so I added a few scriptable tasks to this workflow, but still can't do what I want.

    Any solution plese? or a few best practices to perform this type of workflow? Maybe I missed a workflow can create multiple virtual machines with different names but the same configuration.

    Thanks in advance,

    This can help out you.

  • What is the advantage to affect multiple virtual machines in a data store?

    Hello

    Quite a question stupid and basic, but I can't answer . What is the advantage of having multiple virtual machines in a store of VMFS data instead of having each VM in another VMFS data store? (eg. 3 VMs in 1 data store or 3 data warehouses and each virtual machine in one of them). I can only think about the ease of management for storage administrator because it creates only a single large LUN.

    Thank you

    By allowing multiple virtual machines in a data store, you can run more than 256 virtual machines in a DRS cluster.

    As a host has a limit of 256 scsi identification numbers, which means that it accesses no more than 255 LUNS shared. 1 scsi ID is used for local storage.

    In a DRS cluster as each host must be mapped to the same data warehouses to ensure that virtual machines can be moved on the cluster and run on any of the hosts.

    Now in my life as an architect VMware PSO I saw that a lot of virtual machines that require a single data store. The main reason to isolate a virtual machine on a data store must provide sufficient i/o performance. This can be achieved with other solutions than to isolate a virtual machine on a data store. Having a properly architected storage subsystem is crucial, vSphere can get out of a very large number of the IOPS / s. With technologies such as SIOC and DRS for storage, you can check that the virtual machines receive IO performance according to the needs.

  • Networking between virtual machines on different hosts

    Hello

    I need some advice on the basic approach to networking between virtual machines, each running on a different host machine.

    Consider the following configuration:

    I have a few processes that are running in a Machine virtual Ubuntu. Call this guest1.  I guest1 race inside a real computer running Windows XP SP3 and VMware Workstation 7.x; Call this host 1.

    I have a copy of this virtual machine that I put on another machine.  Call this Guest2.  I have Guest2 running on a separate physical computer, also runs Windows XP SP3 and VMware Workstation 7.x; Call this host 2.

    Now, I would like to guest1 and 2 comments to make networking with eachother.  I wish they were able to ping, SSH, etc., among others.

    This is where I am stuck. I tried setting the virtual machines to use the bridged network mode.  I tried to connect my router on each computer and manually assigning IP addresses to each host and each virtual computer.  When I do this, guest1 can Host1 and Host2 ping, but cannot ping Guest2 and vice versa.

    What is the right way to do this kind of network?  This seems like an obvious application, if you want to perform simulations on multiple virtual machines residing on different computers on the network.

    I apologize if this is the answer elsewhere, I had to dig and was not able to find the solution.

    Thanks in advance!

    Charles

    Guests must be on the same subnet, like 'real' hardware machines.

    1 when you copied the VM and then started, what did answer you the question of copy/move? (this determines if a new MAC address is applied)

    2 view each guest and ' ipconfig/all' results 'ifconfig - a' by the hosts.

    Lou

  • The list of all virtual machines to a host group in Virtual Machine port group

    Ladies and gentlemen,

    I would like to create a powershell script to list all my virtual machines to a host, but a group of Machine virtual PortGroup... It is possible...? I see only found Internet see the VirtualPortGroup of the host...

    Thanks in advance & looks

    All your VMS have a mapping single portgroup or it not with multiple NICs on different port groups?

    If they are all the same, then the following should work:

    Get-VM | Select Host, Name, @{N="PortGroup";E={$_.NetworkAdapters[0].NetworkName}} | Sort PortGroup, Name, Host
    

    If you found this information useful, please consider the allocation of points for correct or helpful.

    Alan Renouf

    http://Virtu-al.NET

Maybe you are looking for