How do the automatic deletion script clone virtual machines

Hello

We use the VM data recovery to clone virtual machines. We would like to clone some VMs on weekly basis but we need a script (or automatically) to remove the existing cloned VM automatically. VDR not clones a virtual computer when there is already a clone of this virtual machine.

The easiest way is to use the Windows Task Scheduler.

See runs a scheduled job PowerCLI Alan post.

Tags: VMware

Similar Questions

  • PowerCLI script - new virtual machine of the model

    Hi all

    I am very new to power CLI scripting, and these days, that I read a lot of help to automate the creation of a new virtual machine based on the model of the virtual machine.  Script that is not that hard, even location new virtual machine on a particular data and in a particular resource pool store is not difficult.  For this I came up with this very basic script/command:

    "New-VM - ResourcePool < resource_pool > - < folder_name > location - Datastore < datastore_name > - name < VM_name > - < template_name >"model

    However, I came across some problems that I can't find information in help or in the forums.  Problem with the above command is VM will be created in the pool of appropriate resources and file as long as they are unique, but if there are multiple instances of resource pool or a folder with the same name as the script spits out a mannequin.

    So for example if I want to create a new virtual machine to the location following Data_Centre = > RootFolder1 = > SubFolder1 = > SubFolder2 and SubFolder2 name is unique that no problem, the virtual machine is created at this location.  However, if the SubFolder2 exists in Data_Centre = > RootFolder2 = > SubFolder1 as well as the virtual machine is created in the folder root of the location of the model.  For example, if the model is in "DC = > Folder1 = > Subfolder1 = > Subfolder2 ' the virtual machine will be created in the folder Folder1

    Any suggestions on how to ensure that the virtual machine is created in the desired folder/location as well as a list of resources?  In my view, there are really smart guys here and I suspect that this issue would not be a problem at all.  Any help would be appreciated.

    See you soon

    It is not a matter of following the right path.

    You can use the location setting to get the exact folder you want. For example

    $dc = get-data center-name DC1

    $folder = get-file-name Folder1-location $dc

    $subfolder = get-file-name Folder2-location $Folder1

    or

    $dc = get-data center-name DC1

    $subfolder = get-file-name Folder2-location $dc

    You will need to find a "place" in the path to your destination folder where it will be unique.

  • Deleting the same files of many virtual machines remotely

    Hi all

    I tried to delete the same file several virtual machines remotely using the following script PowerCLI:

    $a = Get - VM | %{

    foreach ($nic as $_.) Guest.Nics) {}
    Write-output $nic. IPAddress
    }
    }
    foreach ($i in $a)
    {$b = get-WmiOBJECT-query "SELECT * from CIM_DataFile where Name='C:\\test\\deleteme.exe'"-computername $i}
    $b.delete)

    }

    It works perfectly when I run the script on the host virtual machines while I am running the script PowerCLI. When I Connect-viserver to another host however and try to run the script, I get the dreaded "RPC server is unavailable error (HRESULT: 0x800706BA)" for Get-WmiObject.  Virtual machines don't have Windows Firewall and have all TCP/IP, RPC and WMI services started, so who could eliminate any possibility.

    I am also able to run other scripts that use the Get-wmiobject across all virtual machines such as scripts to change the DNS or Netbios name across many machines on different hosts.

    Any comments would be greatly appreciated and please feel free to comment if you know maybe other ways which can delete files on multiple virtual machines in any other way.  Installation PowerCLI to run the script locally on each host would be a laborious process to do.

    Thank you very much!

    Best regards

    To solve the problem with the quotes, you can use double quotes inside the string. Like this:

    «del "«c:\documents and settings\text.exe»»»

    Or you can use for the string single quotes and double quotes inside:

    "del"c:\documents and settings\text.exe"

  • Problem with script to clone virtual machines

    Hello

    I created a script to clone virtual machines on a regular basis around a method posted by LucD and Simon Long here or on their blogs.

    Here is the part that does the actual work:

    $VM = get - VM $Machine.MasterVM
    # Send Email of departure
    .\startmail.ps1
    # Create new snapshot clone
    $CloneSnap = $VM | New-Snapshot - name "Instant Test" - Quiesce
    # Get the managed object display
    $VmView = $VM | Get-View
    # Get the managed folder object reference
    $CloneFolder = $VmView.parent
    # Construction specification clone
    $CloneSpec = new-object Vmware.Vim.VirtualMachineCloneSpec
    $CloneSpec.Snapshot = $VmView.Snapshot.CurrentSnapshot
    # Make the linked disc specification
    $CloneSpec.Location = new-object Vmware.Vim.VirtualMachineRelocateSpec
    $CloneSpec.Location.Datastore = (get-Datastore-name $Machine.BackupDS). Extensiondata.MoRef
    $CloneSpec.Location.Host = (get-vmhost-name $Machine.BackupHost). Extensiondata.MoRef
    $CloneSpec.Location.Transform = [Vmware.Vim.VirtualMachineRelocateTransformation]: sparse
    $CloneName = "$vm - BU - $date"
    # Create clone
    $vmView.CloneVM ($cloneFolder, $cloneName, $cloneSpec)
    # Write newly created VM to stdout as confirmation
    Get - VM $CloneName
    # Remove snapshot created for clone
    $Snap = get-Snapshot - VM (VM-Get-name $Machine.MasterVM)-name $CloneSnap | Remove-Snapshot - confirm: $False
    #Send full email
    .\endmail.ps1

    I want to use in an environment composed of 3 servers ESXi 4.0 with a local data store each. This works well in my test environment, but not in that productive.

    Here, I get this error:

    Exception, calling 'CloneVM' with '3' or the arguments: "it was not correct to specified parameters.
    Spec.Location.pool ".
    C:\script\vm-backup\backup.ps1:98 char: 18
    + $vmView.CloneVM < < < < ($cloneFolder, $cloneName, $cloneSpec)
    + CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)
    + FullyQualifiedErrorId: DotNetMethodException

    In a comment on his blog, made Simon refers to an error in the data store, but it seems very well here.

    By comparing the values of the characteristics to those of my testbed everything looks good, too.

    Does anyone of you can tell me where to look for the problem?

    Thanks in advance

    Christian

    That's correct, 1 by Server default resource pool.

    You can do

    Get-ResourcePool-name resources-site (Get - VMHost - name MyEsx)

    to get the default pool for a specific ESX Server

    CAB, you add a line in your original script

    $CloneSpec.Location.Pool = (get-ResourcePool-name resources-site (Get - VMHost - name MyEsx)). Extensiondata.MoRef

    This should be the correct MoRef

    The message seems to indicate that the target VM already partially exist.

    Remove it before you run your script once again.

  • vCenter Orchestrator - Clone virtual machine with a name like VM_Date

    Hello

    I have try the Workflow "Clone virtual machine, no customization. It works very well but I would like to change settings (cloned virtual machine name), but I don't know how I could do this.

    I would put the cloned vm name: vm_date like this CHDCVSCT0001_31_08_2011.

    Is someone can help me?

    Thanks in advance

    Good day

    Best regards

    Christophe Simond

    No prob. Scripting Self is always the best way to learn

  • Can I use the same windows on my virtual machine?

    I had windows pre-installed in my dell laptop (Latitude E6420). I did not have the cd key but I extracted using a program called Magical jelly bean key finder. Now, I have the following information on my windows installation

    Windows 7 Professional Service Pack 1
    Product no.: XXXXXXXX
    Installed from media "OEM."
    Product ID: XXXXX-OEM-XXXXXXXX
    CD Key: XXXXXXXXXXXXXXXXXXXXXXXX
    Computer name: XXXXX
    Registered owner: XXXXX
    Registered organization: Microsoft
    Now, I want to install linux on my machine and use the current windows in a virtual machine inside the linux host. Is is possible if I completely uninstall this windows of my computer and reinstall the virtual machine with the same key?
    I'm not very familiar with this also can someone guide me what are the steps I have to take if this is possible.

    Hi Andre,

    Thank you for your answer, but this does not completely answer my question. I also read that OEM installation does not install the same windows on another machine (virtual machine is like different machine even if I do this on the same machine) and installation of the mine is OEM type.

    More important still, how install windows in the virtual environment? If I format the computer and install linux, in addition to this install virualbox and install inside windows that use the cd - key and it will work. ? I doubt it because the windows is already activated in this machine.

    The extract of the contract (EULA) for Windows 7 and applies to the retail and OEM of Windows 7 versions. So, Yes, you can reinstall it in a Virtual Machine.

    Yes, you will need to format the machine under Linux, then reinstall Windows 7 in a computer program virtual suitable as Oracle Virtual Box 4.2, VMWare Player 5.0 or VMWare Workstation. You can then use the product key located on the COA sticker to reactivate the license.

  • Set the priority of restarting a virtual machine

    Hello

    I'm trying to set the priority of restarting a virtual machine in a cluster. I worked along THIS DISCUSSION to create this script:

    var myVcClusterDasConfigInfo = new VcClusterDasConfigInfo() ; 
    var myVcClusterDasVmConfigSpec = new VcClusterDasVmConfigSpec() ; 
    myVcClusterDasVmConfigSpec.operation = VcArrayUpdateOperation.add; 
    var myVcClusterDasVmConfigInfo = new VcClusterDasVmConfigInfo() ;
    myVcClusterDasVmConfigInfo.key = VM;
    myVcClusterDasVmConfigInfo.restartPriority =  VcDasVmPriority.high;
    myVcClusterDasVmConfigSpec.info = myVcClusterDasVmConfigInfo;
    var myVcClusterDasVmConfigSpecArray = new Array() ; 
    myVcClusterDasVmConfigSpecArray.push( myVcClusterDasVmConfigSpec ); 
    var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ; 
    myVcClusterConfigSpecEx.dasConfig = myVcClusterDasConfigInfo; 
    myVcClusterConfigSpecEx.dasVmConfigSpec = myVcClusterDasVmConfigSpecArray; 
    Cluster.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );
    

    Where Cluster and VM are objects of the WF input.

    Executions of thoughts scripts, however, in the CR, I get the error «the parameter of {entry.@enum.» InvalidDasConfigArgument.EntryForInvalidArgument} is not valid for the cluster.

    It's simple... but I just can't cope.

    Thank you guys

    Also I just realized... that the method I used is deprecated... grrr

    Here's the correct one:

    var myVcClusterDasVmSettings = new VcClusterDasVmSettings();
    myVcClusterDasVmSettings.restartPriority=VcClusterDasVmSettingsRestartPriority.fromString(priority);
    
    var myVcClusterDasVmConfigInfo = new VcClusterDasVmConfigInfo();
    myVcClusterDasVmConfigInfo.key=VM;
    myVcClusterDasVmConfigInfo.dasSettings=myVcClusterDasVmSettings;
    
    var myVcClusterDasVmConfigSpec = new VcClusterDasVmConfigSpec() ;
    myVcClusterDasVmConfigSpec.operation = VcArrayUpdateOperation.add;
    myVcClusterDasVmConfigSpec.info = myVcClusterDasVmConfigInfo;
    
    var myVcClusterDasVmConfigSpecArray = new Array() ;
    myVcClusterDasVmConfigSpecArray.push( myVcClusterDasVmConfigSpec );
    var myVcClusterConfigSpecEx = new VcClusterConfigSpecEx() ;
    var myVcClusterDasConfigInfo = new VcClusterDasConfigInfo() ;
    myVcClusterConfigSpecEx.dasConfig = myVcClusterDasConfigInfo;
    myVcClusterConfigSpecEx.dasVmConfigSpec = myVcClusterDasVmConfigSpecArray;
    task=ClusterName.reconfigureComputeResource_Task( myVcClusterConfigSpecEx, true );
    
  • VMWare Fusion for Mac - how much space HARD drive is my virtual machine taking?

    So, I am running VMWare Fusion on my MacBook Air, and I'm under low HARD disk space.  My Mac storage utility tells me that I have a ton of capacity used in the 'Other' bucket.  According to me, this bucket is where live VMWare Fusion.  As I understand it, technically, my complete operating system of Windows (including all files) is contained in a single file on the Mac side.  Is this correct?  Is it possible to see what capacity takes up my whole Windows Operating System (Virtual Machine)?  I hope this makes sense.  Thanks in advance for your comments!

    -Chill

    ChillOne wrote: as I understand it, technically, my complete operating system of Windows (including all files) is contained in a single file on the Mac side.  Is this correct?

    No, it's not correct!  A Virtual Machine is composed of many files and folders according to how it configured and used.  On a Mac if created natively by VMware Fusion using values by default so all the files that make up a virtual machine are in all of the Virtual Machine that is structurally nothing more then a regular folder except the extension .vmwarevm, it is treated differently by the launch in OS X Services.  Take a look on: work with Virtual Machine packages

    The files that make up the Virtual Machines from Windows/Linux systems and other places my being in simple ordinary folders.

    Is it possible to see what capacity takes up my whole Windows Operating System (Virtual Machine)?

    You can also see statistics for a given Virtual Machine by selecting Virtual Machine in the library because it displays size information, as well as on the General form of a virtual machine; s parameters.  Or look in the Finder and see the release of Get Info for the packaging of the Virtual Machine or the folder that contains the files that make up the Virtual Machine.

  • Need a script for virtual machine availability

    I know there is a metric for sys.uptime.latest which pulls the elapsed time in seconds surveyed of the virtual machine startup. Two questions

    This allows VM cacluate uptime in a perspective of avalability host?

    It only takes into account availability time between reboots to the vCenter level, or it takes into account all the running time? (example: uptime since a restart triggered via vCenter client vs a shutdown - r resulting in a virtual machine)

    Does anyone have a scipt that could be used or modified to give VM uptime? PowerGUI has a performance data plugin which can show it on a unique basis of VM. But I need to interview all the data for the whole vCenter and all virtual machines.

    Thank you!

    The metric of sys.uptime.latest gives you the time since the last poweron of the virtual machine.

    All reboots of BONE, of in the comments or via the vSphere client, do not reset the counter.

    This script gives you a report of the availability for all your virtual machines

    $vms = Get-VM Get-Stat -Entity $vms -Stat sys.uptime.latest -MaxSamples 1 | ` Select @{N="VM";E={$_.Entity.Name}},@{N="Uptime";E={$_.Value}}
    
  • Need help updated the VMX file on several Virtual Machine

    All,

    Can anyone help with a problem I'm having?  Here is a brief explanation of what is happening and what we need to solve.

    Recently we found out that we need to add a line in the file VMX of several virtual machines.  In the past, I was able to do this, but would have cold start the virtual machine for the changes to take effect.  Starts cold won't be a problem, because we can program it.

    However, no one knows a way to add this line in the file VMX virtual machines in a cluster.

    Here's the line I need added:

    Devices.hotplug = "false".

    Here is a script that was used earlier (esx 3.0 days) to keep the VM tools updated on reboot.  At this point, if the virtual machine has been turned on, this change could not do through the UI.  However, this script worked to update the .vmx file and then we have cold reboots for the changes to take effect.

    Get-viserver - < Server > - < user > - < password >

    $viview = get-Cluster-name NOMCLUSTER | Get - VM | foreach-object {get-view ($_.ID)}
    $viview | {foreach-object
    $vmConfigSpec = new-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = new-Object VMware.Vim.ToolsConfigInfo
    $vmConfigSpec.Tools.afterPowerOn = 'True '.
    $vmConfigSpec.Tools.afterResume = 'True '.
    $vmConfigSpec.Tools.beforeGuestStandby = 'True '.
    $vmConfigSpec.Tools.beforeGuestShutdown = 'True '.
    $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle".
    $_. ReconfigVM ($vmConfigSpec)
    }

    The exact script can be found in Disable HotPlug

  • Can I change the RAM available on a virtual machine without having to reboot?

    I would like to know if there is an option to change the RAM available on a virtual machine without restarting the virtual machine. I saw this old news item that says that it is

    possible (http://news.cnet.com/8301-1001_3-10044031-92.html), but I don't know how to do it. Any suggestions?

    Thanks in advance.

    Arne post, called PowerCLI: toggle the function add Hot VMs, shows how.

  • Not possible to export a list of virtual machines that are created in the past 7, 30, 120 and 180 days since an imported csv file containing the date of creation of virtual machine

    Not possible to export a list of virtual machines that are created in the past 7, 30, 120 and 180 days since an imported csv file containing the date of creation of virtual machine. My questions is the correct statement to the variable: $VmCreated7DaysAgo: $_CreatedOn "-lt" $CDate7.

    # #SCRIPT_START

    $file = "C:\Users\Admin\Documents\WindowsPowerShell\08-18-2014\VM-Repo.csv".

    $Import = import-csv $file

    $VMCreatedLast7RDayRepoFile = "C:\Users\Admin\Documents\WindowsPowerShell\08-18-2014\Last7Days.csv".

    $start7 = (get-Date). AddMonths(-1)

    $CDate7 = $start7. ToString('MM/dd/yyyy')

    $VmCreated7DaysAgo = $Import | Select-object - property name, Powerstate, vCenter, VMHost, Cluster, file, Application, CreatedBy, CreatedOn, NumCpu, MemoryGB | Where-Object {$_.} CreatedOn - lt $CDate7} | Sort-Object CreatedOn

    $TotalVmCreated7DaysAgo = $VmCreated7DaysAgo.count

    $VmCreated7DaysAgo | Export-Csv-path $VMCreatedLast7RDayRepoFile - NoTypeInformation - UseCulture

    Write-Host "$TotalVmCreated7DaysAgo VMs created in 7 days" - BackgroundColor Magenta

    Invoke-Item $VMCreatedLast7RDayRepoFile

    # #SCRIPT_END

    You can use the New-Timespan cmdlet in the Where clause, it returns the time difference between 2 DateTime objects.

    An example of this cmdley

    New-TimeSpan-start (Get-Date). AddDays(-7)-end (Get-Date). Select days - ExpandProperty

    In your case, you could do

    Where {(New Timespan-démarrer ([DateTime] $_.))} CreatedOn) - end $start7). {7 days - gt}

    But beware of negative numbers.

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

  • Is it possible to hide the news of Vmware's Virtual Machine?

    Hello just a small matter of team.

    We have 5 ESX

    Is it possible to hide the news of Vmware's Virtual Machine during the creation of the Virtual Machine (not in registry) that we have a lot of VM?

    Start > run > msinfo32 >

    Thank you

    GoldTipu

    Hello

    It is possible that you could change some things in the registry, but there are many other "clues" as something being a virtual machine, such as the presence of tools VM, MAC address, drivers, etc.

  • How to stop the automatic deletion of the Recycle Bin?

    How can I stop the automatic task of cleaning my trash

    Hi Alice,.

    For each drive on your computer certain limit space is assigned for the trash. If you delete a file that is greater than the allocated space, this file will not fall to the trash after deletion.

    To manage this space, right click on Recycle bin select Properties, on the general tab, under the section selected location setup check the custom size and keep the size you want. If the following radio button is checked then when deleting files it will go not to trash gets it deleted directly.

Maybe you are looking for