How to delete a virtual machine in a script


Hello

I want to delete a virtual machine with a VCO script, I wouldn't use the action item named destroyVM. I explain why I wouldn't use, because in my script, I do this action:

1. I list all VM in a specific folder name is different date servername-today ' today and powered OFF.

2. I would destroy each VM in the list.

But when I would simply test the following command:

System.getModule("com.vmware.library.vc.vm").destroyVm ("VMName");

I get the following error message:

TypeError: Cannot read property "runtime" undefined (name of the dynamic Script Module: destroyVm #52993)

I search on google and VMware blog, I can't find anything to help me!

If someone has an idea, you are welcomed to answer me.

Thank you in advance

Good day

Best regards

Christophe

Hello

If you have access to vm.name or vm.runtime, you can access the vmobject.

Therefore, you don't have to search again. I'm confused...

(1.) what is folderObject?

2.) check your if condition. It is not '&' what you want, but «&»

(3.) getAllVMsMatchingRegexp() returns an array of vmobjects, not a single vmobject. VM names are NOT unique.

Maybe a small example can help:

var vmArray = VcPlugin.getAllVirtualMachines();
for (var vmIndex in vmArray)
{
    if ((vmArray[vmIndex].runtime.powerState == VcVirtualMachinePowerState.poweredOff) && (vmArray[vmIndex].name == "SCT-Test-01_12_2013"))
    {
        System.getModule("com.vmware.library.vc.vm").destroyVm(vmArray[vmIndex]);
    }
}

Tags: VMware

Similar Questions

  • Deletes a virtual machine of vCenter possible?

    Hi all.

    We used to be a Horizon view manual pool composed of virtual machines
    from vCenter server. In a single operation for removal of VM in view, we

    wrong selected pool and confirmed the deletion. The

    operation put merrily and when we realized the error, we

    find vsphere client that all VMs funds (a lot of them

    were running) in the manual pool view both were removed from the inventory

    and from the disc in vCenter server.

    This offends and confuses us. It is commonly accepted that it is
    Cannot delete a virtual machine running of vCenter: vSphere client no
    won't give you a possibility to do so, and doing so in a CROWD ends by default.
    But the view above disaster might suggest otherwise.

    I have two questions:
    1. is it possible to delete a virtual machine running of vCenter?
    2. If so, how to prevent in vCenter?
    3. (somewhat off topic) is it possible to come up with any hacking or

    This makes it impossible to remove vm disk Office while being

    able to manipulate the view of the pool? We prefer to rather in vCenter.

    =====================================
    The mistake that we made to remove all the Horizon view desktop VMs:
    1. login to VMware view Horizon administrator.
    2. based on the inventory, select the pool.
    3. in the view of the pool, select the tab "inventory."
    4. Select and right click on a desktop PC, select 'delete pool... '. »
    5. confirm the deletion.

    Software used:
    vCenter Server: 5.5.0, 1945274
    View of the horizon: 5.3.1 generation-1634134

    Kind regards
    Nathalie Sun

    Post edited by: sunrenjie6

    Hello Sun Nathalie,

    Finally, I was able to create your question on my test bench, but as I said earlier, it is not possible to remove a power on the virtual machine, which was true. When I deleted the pool which consists of power on VM, I saw in the VC that VM were power off first and delete.

    I also talk to the team from the horizon and they said that this device is designed this way to support several other features. To save accidental deletion of the s VM that they introduced the warning message.

    Sorry for your loss.

    Thank you

    DJ

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

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

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

  • Delete the virtual machine to the specified date

    I'm trying to write a script to remove a virtual computer on a certain date.  Currently, I want people to add this in the name of the virtual machine "VMname_Delete-/ 1/1/14", I then search for the virtual computer with:

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"}

    With that, I'm sure that the correct VM is selected, and I tested it with virtual machines to make sure.  Now comes the hardest part (at least for me), I want to take the date to which belongs the VM name, convert it to a DateTime and then compare it to the current date.  If they match, I want to remove the virtual machine.  I tried something in the sense of:

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | foreach {$_ .name-split "-"}

    Which of course divide the table edge, and on tests, I had an output similar to:

    VM_Delete

    01/01/14

    Of course, now I don't know how to finish the rest.  I thought that the script would be something like:

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | {foreach}

    If (($_.name-split «-»)-[DateTime] - game (get-date-format ' MM/dd/yy'))

    {Remove-VM - VM $_ - DeletePermanently}

    }

    I don't see the logic in my head, but of course, I just can't write they way I think it should go.  Any help is appreciated.

    Perhaps you could do something in this direction

    $now = get-Date

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | {foreach}

    $dt = [datetime]($_.) Name.Split('-') [1])

    If ($dt - lt $now) {}

    Remove-VM - VM $_ - DeletePermanently

    }

    }

    With the use of the index ([1]), we select the date part of the name of the virtual computer.

    Then we have "cast" the string into a DateTime object.

    Note that typeface could cause problems, depending on the culture settings you use.

    Worse, divide you the date on the character string ' / ' and then generate the DateTime object as follows

    $now = get-Date

    Get - VM | where {$_.name - cmatch "Delete-\d\/\d\/\d"} | {foreach}

    $dummy, $year $day, $month = $_. Name.Split('-') [1]. Split('/')

    $dt = get-Date-day $day - month $month-year $year

    If ($dt - lt $now) {}

    Remove-VM - VM $_ - DeletePermanently

    }

    }

  • Deleting a virtual machine

    I'm having a very difficult time trying to find how to delete a machine virtual vcenter through the SDK (the doc leaves much to be desired). I found the method unregisterVM() of the command VimPortType (just the syntax, no explanation of what it does), but after using it, it just gets rid of the VM inventory - all files are still on the data store.

    I want to get rid of the files as well as registration in the inventory. I found a method

    unregisterAndDestroyTask() , 

    but there is also no explanation of what it actually does.

    Can someone tell me please how to get rid of a vCenter virtual computer and the data store completely?

    There is a generic 'delete' method called Destroy_Task() http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.ManagedEntity.html#destroy which is applicable to different types of objects, including a VirtualMachine, HostSyste, Datacenter, etc depdning on the object, it will do different things. For a virtual machine, it will remove the virtual machine and it has associated the disc for a HostSystem, it will just remove it from vCenter

    The UnregisterVM_Task() is just, that he cancels his registration vCenter or ESX (i) inventory, but leaves his records intact. If you want to destroy everything, you want to use the Destroy_Task()

  • WS8... Delete the virtual machine list

    I have 8 Workstation for Windows (running on Windows 7 x 64), just put at level towards the new generation today. The other day, I deleted a VM by going to my directory and just delete the VM folder. Now 8 Workstation, it still shows the VM it but when I click it, it gives me an error (not found) as it should.

    If I right click on this missing virtual machine, it gives me just an option to play. How can I remove these virtual machines in the list if there is not a virtual machine it more? Is there a file I can edit or a parameter somewhere? I have searched but can't see to find.

    I am looking for and looked through 10 pages here and not see this question, unless I missed it, so please give me a link and close this post.

    Thank you!

    Edit
    C:\Documents and Settings\userApplication Data\VMware\inventory.vmls

    and if still necessary
    C:\Documents and Settings\userApplication Data\VMware\preferences.ini

  • How to cancel a virtual machine?

    Morning,

    After trying to return to a capture instant hot our vcenter server is suspended with an error that the cpu is in a different family.

    The virtual machine has not changed hosts (I think) I understand that the way to solve this problem is to re - save the vm on the host.

    We use the ESXi 4.1.  I can't find the orders or instructions on how to do it.

    Any help would be appreciated.

    Thank you

    The virtual machine tries to regain the State of snapshot saved in the following file.

    06:25:50.938 25 Apr: vmx | CPT: Restoration of control point/vmfs/volumes/4ca074a5-7f211820-c561-0023aef861ac/GAL-VC01 /GAL-VC01 - Snapshot3.vmsn

    Unless you discover on which host the snapshot was taken or what happened (e.g. BIOS update) during the snapshot date and now, you can delete this file. The result would be comparable to a system reset.

    André

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

  • How to install the virtual machine to ISO image

    Rather than burning a CD from ISO images downloaded from each OS you want to build a virtual machine it would be more convenient to use the ISO image directly. How can I achieve this?

    Create the virtual computer with CD player.

    Double click the CD drive in the virtual machine properties.

    Select USE AN ISO IMAGE

    Navigate to the image.

    and also you can refer to this link

    VMware Workstation 12 Pro Documentation Center

    you're installation uses several CDs pleae follow this procedure

    First duty (if the customer has a button for this) eject the CD in the comments, then ctrl-alt to focus the host, right click on the CD icon in the bar area of low right state of the workstation user interface and select disconnect; repeat, and then click edit. Select the image ISO next necessary; reconnect; then click the mouse back in the window of the customer and to know that the next CD is loaded.

  • How to migrate a virtual machine of vsphere vsphere 4 5

    I have a vsphere 4 and a 5 of vsphere, I want to migrate a virtual machine of vsphere vsphere 4 5

    my method is export ovf model and deploy the model of the FVO in vsphere 5, but it shows "end of file EGGS reached while looking for: * hard.

    How can I work my problem

    Thank you very much

    Hello

    Why are you trying with VMware Converter?

    https://my.VMware.com/Web/VMware/info/slug/infrastructure_operations_management/vmware_vcenter_converter_standalone/5_0

    It's the right tool for this kind of tasks/migration

    However, if you share with us details about your environment, we can help you more accurately.

    Concerning

Maybe you are looking for

  • iTunes, iTunes Store

    Dear Guys! At glance... I got a song in iTunes Store today and make "shufle a song..." Listening listen hierarchical from that... Come to second I like to buy it from the same album, downloaded... touch 'play' won't play! WHY? Thank you for attention

  • Need to display more than two columns in the game now (library view)

    The current reading list (under the library, not the instant game tab menu tab a top of the player) shows only two columns, the title and duration.  I can't add more columns by selecting choose columns, or restore the columns.  I have this problem wi

  • Recover files deleted/dumped trash jpeg?

    A program or procedure exists which allows to recover jpeg files after being removed/dumped in the garbage area in an XP system.   The old BACK would simply attach a? at first, name and a person could find and rename deleted files!  XP does the same

  • Module of persistence and Windows Media Player has stopped working Vista

    I get a message when I reboot the persistence module has stopped working. Windows Media Player has also stopped working.

  • BlackBerry Internet-accessing smartphones

    I'm having a probleming at the opening of the internet.  I get a window that opens by saying: "this is a problem when trying to render the page.  He began to do this last part of the time, and now it seems to be all the time to come.  Can someone hel