Script for a specific virtual machine vmotion

I play a few trials of benchmarking on VMS 2. part of the test is to migrate a virtual computer when certain I/O points are reached. I wrote a simple script for vmotion one of these virtual machines:

$vm = get-VM-name Bench_VM | Get-View

$chost = $vm. $host.name

If ($chost = ESX01.company.com)

{

Move-VM VM - Bench_VM - Destination ESX02.company.com

}

on the other

{

Move-VM VM - Bench_VM - Destination ESX01.company.com

}

I get an error:

The term 'ESX01.company.com' is not recognized as the name of a cmdlet, function, script file, or an executable program. Check the spelling of the name, or if a path has been included, make sure the path is correct, and then try again.

What I am doing wrong?

Thank you

There are 2 problems with your script.

(1) you can't get hostname like this

(2) comparison of PowerShell uses the operator - eq.

This should work better

$vm = Get-VM -Name Bench_VM
$chost = ($vm | Get-VMHost).Name
if ($chost -eq "ESX01.company.com")
{
     Move-VM -VM Bench_VM -Destination ESX02.company.com
}
else
{
     Move-VM -VM Bench_VM -Destination ESX01.company.com
}

____________

Blog: LucD notes

Twitter: lucd22

Tags: VMware

Similar Questions

  • How the scripts for the new virtual machine storage profile

    Hey all,.

    I have a long script that I've been put together so that our operations people size new virtual machines.  I ask a series of questions for such things as the VM name, cluster, VLAN, plug hardware, OS/template, etc.  I use LucD method to create a temporary copy of a customization OS specification to insert a static IP address.  I have everything works except that I can't figure out how this script drop-down list:

    storageprofiledropdown.jpg

    vSphere 5.0, any VCD.  Looks like it should be pretty simple, but I can't find anything on how to do it.  It would be nice to choose this in the New - VM cmdlet somewhere, as well as the use of the GUI.  Any ideas?

    Throw a glance PowerCLI 5.8, when it is available, there is a charge storage profile cmdlets in there (as we showed in our VMworld session this week).

  • Perl script for deploying a virtual machine template

    Am looking for a perl script for the deployment of the existing models on Vsphere virtual computer. So far, I got access to the virtual machine. I saw that there is a utility called new-vm on the powershell. I'm running a linux machine and therefore seeking an alternative to perl. Kindly give me pointers or help me with some documents.

    Thank you!

    Well, I managed to create a virtual machine from the template using the vmclone.pl script, which is part of the vmware sdk. But post creation that he's not leaving means VM State is off. I'll have to find a way to start the virtual machine as well.

  • Script to create multiple virtual machines model works is not for the network adapter variable

    We are working on a script to create multiple virtual machines from a template. The script works fine, but when we try to include commands to set the NIC to a group of specific ports on a dvswitch script errors on. Here's what we have so far. This script (less network variables) works, but we would like to include the network configs in the script as well.

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

    This is the part of the script that configures the network/dvswitch adapter... but does not work properly.

    $myResourcePool = get-ResourcePool-name DQOL

    $dsName = get-Datastore-name "DQOL-DS01.

    $myTemplate = get-Template-name "DQVTemplate".

    $distributedSwitchPortGroup = get-VirtualSwitch-distributed - name "CVE-dvS04-Nexus - k 5 | Get-VirtualPortGroup-name '979-DQ-SHARED '.

    New-VM-name MyVM1-model $myTemplate - Networkname ResourcePool - $myResourcePool - OSCustomizationSpec $mySpecification $distributedSwitchPortGroup - Datastore

    (Get-$dsName data store)

    New-VM-name MyVM2-model $myTemplate - ResourcePool $myResourcePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    _____________________

    !!!!!!!  This part works, but without specifying a network/dvswitch... card!

    $myResourcePool = get-ResourcePool-name DQOL

    $dsName = get-Datastore-name "CVE-SAN-ISG-DS02-02ef.

    $myTemplate = get-Template-name "DQVTemplate".

    New-VM-name MyVM3-model $myTemplate - ResourcePool $myResourcePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    New-VM-name MyVM4-model $myTemplate - ResourcePool $myResourcePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    Here is the error we get:

    New-VM: all parameters can be resolved by using the specified named parameters.

    C:\Users\capuanoj\Desktop\Create-multiplevms-fromtemplate.ps1:6 char: 7

    + New-VM < < < <-name MyVM1-model $myTemplate - Networkname $distributedSwitchPortGroup - ResourcePool

    ePool - OSCustomizationSpec $mySpecification - Datastore (Get-$dsName data store)

    + CategoryInfo: InvalidArgument: (:)) [new-VM], ParameterBindingException)

    + FullyQualifiedErrorId: AmbiguousParameterSet, VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

    You cannot use the - model and Networkname - parameters of the cmdlet New - VM in a single order, because both are in different parameter sets. You must first create the virtual machine and then use the cmdlet Set-NetworkAdapter to change the portgroup of the virtual machine. As in example 4, assistance from cmdlet Set-NIC:

    --------------  Example 4 --------------

    C:\PS>$myNetworkAdapters = Get - VM | Get-NetworkAdapter-name "NIC 1.
    $myVDPortGroup = get-VDPortgroup-name MyVDPortGroup
    Together-NetworkAdapter NetworkAdapter - $myNetworkAdapters - $myVDPortGroup Portgroup

    Retrieves all network named "NIC 1" cards of all virtual machines and connects to the specified distributed port group.

  • best way to specify a folder for a new virtual machine

    Hello

    I am currently working on a system that has the following file structure:

    DC1

    Prod

    Linux

    Windows

    Other

    Dev

    Linux

    Windows

    Other

    Beta

    Linux

    Windows

    Other

    What is the best way to specify a specific folder for a new virtual machine. At the Moment so I just say Linux it is said that there are several files with the same name. I discovered a way to get the good record, but it's very nearby. Any comments would be much appreciated.

    Kobus

    Perhaps the function in my folder through post might help?

  • Assign a port to a specific virtual machine network and combine ports

    Hello

    I have two questions.  1. is it possible to assign a specific to a single virtual computer network port? and 2. I can aggregate multiple physical port to act as 1 and have a virtual port to VMS?

    I'm new to VMware so please forgive me if this is a fundamental issue.  I tried googleing the issue but did not have much luck.  I have a Dell R710 with 4 physical network ports.  Currently all the virtual machines on the host sharing a port.  I would like to use one of the ports and assign it to a specific virtual machine and only this VM.  One of the virtual machines is my / home server and NFS exports him / home dirs to other systems.  This virtual machine will be cumbersome to use network.  I want to assign its own network for its traffic port does not impede the movement of other virtual machines.

    I would also like to consolidate other ports into a single virtual port.

    If you can tell me a document that explains how to do this, I would be very grateful.

    Thank you

    [email protected]

    Welcome to the VMware communities forum.   With the default installation of ESXi, a single virtual switch (vSwitch0) is created using vmnic0.   If you want to add additional NIC ports simply go to Configuration > network and then click the properties link to the vSwitch.  Click network adapters, and then click Add to add another NIC port.   ESXi then balance the network traffic load.

    You could dedicate a NIC port to a virtual machine, but possibility of ESXi to balance the traffic load I would simply add additional NETWORK adapter ports to vSwitch0.  If your network needs simply to include VM and management traffic, then I would have simply put all 4 ports NETWORK card in vSwitch0 and let ESXi manage traffic.  This way, you get as much redundancy.

    If you use network storage for your virtual machines (such as iSCSI) then you can consider segment this traffic.  In this case create you a new vSwitch and that a link to 2 (i.e. 2 NETWORK ports for iSCSI) NETWORK ports and then other 2 NETWORK ports in vSwitch0 for ranks of VM traffic.

    VMware now offers a right to training free ESXi.  See the first link below.

    Dave
    VMware communities user moderator

    ESXi Essentials free training / eBook offer

    Now available - VMware ESXi: planning, implementation, and security

    Also available - vSphere Quick Start Guide

  • Change the default options for a NEW virtual machine in ESXI 5.1

    Hello

    I am looking for a solution change the 'default' options for a new virtual machine created in ESXI 5.1

    I want to have parameters such as 'cpu/memory HOT-add' default to enabled instead of disabled.

    There may be more options to change to a new virtual machine.

    All those who have an option to change the 'default' options for new virtual machines?

    THX

    You can change the/etc/vmware/config of vSphere host file and add the lines mem.hotadd = 'TRUE' and vcpu.hotadd = 'TRUE '.
    The settings then apply to any VM on this host when virtual machines are turned on...

    I just tried this on a 5.1 ESXi host and it seems to work perfectly...

    / Rubeck

  • 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).

  • Impossible to change the path for the shared virtual machines

    Hello

    as long as user root, in the Preferences menu, shared, VMs when I change the location and

    (1) push apply 1 time, the path is created in the right place on the hard drive but when I want to share a virtual machine and move toward this path, the default path is the default: / var/lib/vmware... not the one created by the menu setting.

    Cannot change the location for the shared virtual machines.

    (2) push apply several times: odd error menu

    vmware.jpeg

    OS: Linux mandriva 64

    Any ideas?  Is this a way to manually change the path in a config file?

    Best respect

    Out of work station - stop pass.
    Then edit datastores.xml - don't know where the files on Linux - I expect it be in/etc/vmware/hostd or something like that

  • Need a script to list all virtual machines on specific data warehouses

    I am trying to find a way to list all virtual computers on specific data warehouses. I use vSphere 5.1 and so far I got this:

    Get-Datastore. where {$_ .name - like ' * XXX * ""} | Get - VM | Select name, @{N = "Datastore"; {E = {Get-Datastore - VM $_}} | Sort name | FT - one

    This kind of work, but it would be perfect if I got this:

    -Group data store

    -Unique virtual machines (VMS to report only to the data store where the VMX)

    Any help appreciated.

    I relied on the fact that the first in the list would be the data store that holds the VMX, which apparently is a misconception.

    Try like this

    Get-Datastore-Name ' * xxx *' |

    Get - VM | Select the name,

    @{N = "Datastore"; E={$_. {{ExtensionData.Config.Files.VmPathName.split ('[]') [1]}} |

    Tri-objet-property data store name |

    Format-Table - AutoSize

  • Powecli set IP for a Windows virtual machine, IP pool

    Hello

    I followed all the steps in this article https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.vsphere.networking.doc%2FGUID-DBF79F52-925A-4D0D-893C-49B911D3AC54.html and I need the following to make it work,

    1. pursuant to article when an IP pool is configured, mapped to a portgroup VM in this network is VAPP options enabled and I put it in the static pool of IP.

    2. so when a virtual machine is on the network adapter in the virtual machine must be assigned an IP address from the IP pool.

    3. but VM NIC adapter gets never assigned with an IP address from the pool and VMware have confirmed this IP pool do not have a capacity to push an IP address to the virtual machine.

    I'm looking for a script that can be kept inside the virtual machine and pull an IP address pool option or VAPP machines IP and assign the adapter NIC VM (Windows). Probably via the VMware tools? Let me know any possibility for that?

    The use of IP pools is like poking yourself in the eye. It feels better when you stop

    If you cannot use DHCP and must use IP pools there are a ton of up front configuration mucking about to make:

    1. Follow the first article you have linked
    2. In the options of vApp for the VM in properties and then create a property for each of the things you want to get the pool of IP (IP, etc.). When to create the entries under type select dynamic property can find the correct entry in the drop-down list then the values come from the IP pool
    3. Set up an auto start task (a scheduled task that starts at the start) in your model of virtual machine to run a script that:
      1. Expect that VMware tools start
      2. Run vmtoolsd to get the values of vApp in the VM in XML format
        1. 'C:\Program VMware Tools\vmtoolsd.exe-' cmd 'info-get guestinfo.ovfEnv '.
      3. Parse the XML file to extract the intellectual property, etc..
      4. Run the OS commands (netsh, wmic, vbScript (wmi) or Powershell (perhaps native, perhaps wmi according to version)) to take the values from the XML file, and then set the operating system options

    Outside this configuration he plays poorly as the 'network' in the dynamic property is bound to a group of specific ports. If you try to deploy widely, this means a VM model by group of ports (blech!)

    Hope this help to help you started (or persuade you to use DHCP)

  • Run the script file from a virtual machine

    Hello

    I have a script (c:\script.ps1) I want to run on a virtual machine. Can someone tell me how to do?

    When I want to run the single command on vm I follow these steps:

    > > $cred = get-Credential

    > > Invoke-VMScript - win1 VM - GuestCredential $cred - ScriptText "dir".

    but I don't know how to put the script in a variable so that I can place it after the parameter - ScriptText.

    PS Script is not on the virtual machine, it's on the computer I have installed PowerCLI.

    LucD thanks for help

    I managed to do this way:

    $script = Get-Content - Path C:\script.ps1 | Out-string

    Invoke-VMScript - win1 VM - GuestCredential $cred - $script ScriptText

    without out-String I received the error "failed to convert System.Object [] to the System.String type.

  • How to set up the generic dashboard for the specified virtual machines

    I have two question about "generic dashboard":

    1. I use the tag to classify certain virtual machines by role QA, DEV or PRD. If I select "Kind of resources", and then select all VM under a label, window "metrics selector" will be watch only "vCenter generated Operation Manager", it does not show metric VM. How can I see it?

    2. If I select the 'Resources' mode, then I'll be able to see the VM metrics on the window "metrics selector", but I must key in each VM name "Label to the area", it takes a lot of time if I have a lot of VM, is there no matter what symbol I can use to match this field with name column "resource"?

    Mode 'Resources like' or 'Resource', both ok for me, I want to just install a widget to display using the specified CPU VM real fast.

    Any information is appreciated!

    You will see that vC generated Ops metric because you are looking at the tag, which is a resourcekind. This switch of resources is "not" a filter label, these are the actual resources. If you want to see all the virtual machines, select the resourcekind 'virtual machine '.

    Generic dashboard is rarely used to show - all - kinds of resources, it is generally used for static selection for specific purposes. If you want to display all types of a resource type and apply a tag filter, you can select a different widget to display this information.

    There is no symbols that can act as wildcards, as you suggest. When you are 'kind of resources' mode, you need not fill out a label for the box.

  • Activation of CBT for all ESX virtual machines?

    Hello

    This favourable CBT for all of the Virtual Machine that is managed by my Virtual Center is a good idea or not supposed to be due to General files CBT?

    I have to restart all virtual machine once I activate the option of CBT manually one by one but the vSphere Console modify settings for each virtual computer?

    Your help and your help would be greatly appreciated.

    Thank you

    Avamar, not sure but I am sure that it provides an option to activate the CBT. NetWorker offers a script to activate the CBT. However, IIRC there is a problem with the file level restore when using CBT with version 7.6.

    André

  • Specific virtual machines of the user

    Hello

    My company will buy VM Fusion for the Mac Mini. The Mac Mini that we have is joined to the domain. Domain users have administrative privileges. What I could see, is when a domain user 1 installs an operating system called, area 2, another user who logs on to the same mac mini, is not able to see the guest operating system. Only 1 user is able to view the guest operating system. Is it possible that any kind of user (local / domain user) can use the guest operating system? Or is the only specific user?

    Basically, I would like to have the guest operating system visible to all users, is it possible?

    Instead of creating the Virtual Machine in the default location, "/Users/$ {USER} / Documents/Virtual Machines.localized /" place them in "/ Users/Shared/Virtual Machines / ' and make sure that all users have full access to the folder" / Users/Shared/Virtual Machines / "as well as any Virtual Machine Packages of documents including all the files in the Document Package.

    Take a look at the section 'Sharing of Virtual Machines between users' in the Beginner's Guide to VMware Fusion.

Maybe you are looking for