VMware Cloud Community
valot
Enthusiast
Enthusiast

I want to configured a task to clone a virtual machine each day with a different name: possible ?

Hi all,

     I'm trying to find a way to configured an automatic task (scheduled) to clone a virtual machine

with a different name, each time, with date-time for example.

     Directly with virtual center seems not possibe, a script could resolve my issue ?

     Tks for all reply

     Bonne Année 2011

     Happy new year 2011

0 Kudos
16 Replies
Troy_Clavell
Immortal
Immortal

you may be able to find your answer in the PowerCLI Community.  This will probably be your best method, other than creating multiple scheduled tasks within vCenter

0 Kudos
valot
Enthusiast
Enthusiast

Tks for the reply

One point ==> I'm using Virtual Infrastructure 3 (VC2.5 U4 and ESX3.5 U5bis)

Best regards.

0 Kudos
Troy_Clavell
Immortal
Immortal

your best bet is still PowerCLI

....on a side note, it's not a good idea for your ESX Hosts to be on a newer build than your vCenter.  Older vpx agents may cause weird issues.  I would suggest upgrading vCenter to, atleast 2.5.0U6

valot
Enthusiast
Enthusiast

Hi all,

I just need a script to rename a virtual macjhine with the current date time ....

Is there somebody to help me ?

tks a lot

best regards.

0 Kudos
RvdNieuwendijk
Leadership
Leadership

To rename a virtual machine to the current date and time you can do:

Get-VM YourVM  | Set-VM -Name (Get-Date) -Confirm:$False

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
LucD
Leadership
Leadership

Note that the rename with the Set-VM will only change the Displayname of the virtual machine.

The folder and files for the virtual machine will still have the same name as the original name.

It is better to create the machine each time with the correct name.

This avoids all problems.

New-VM -Name (Get-Date).ToShortDateString() -VM (Get-VM -Name "original-vm") ...

You will probaly have to add other parameters to the New-VM cmdlet like Datastore, VMHost ...


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
valot
Enthusiast
Enthusiast

Hi LucD,

I already aware that when you rename a virtual machine the corresponding directory is not renames, only the display name.

I just want to rename each day a virtual machine with the date time after its name...

Tks for your reply.

0 Kudos
valot
Enthusiast
Enthusiast

Hi,

Tks for your reply.

I haven't the Get-* command as I just installed the " Vmware VIPerl Toolkit " (VMware-VIPerl-Toolkit-1.6.0-104313).

I want to run a batch (windows) every day to rename a virtual machine witht he current date-time.

Have you the same command on a perl script ?

tks a lot.

0 Kudos
RvdNieuwendijk
Leadership
Leadership

Why don't you install PowerCLI also and give it a try. You can run PowerCLI scripts from a command file or as a scheduled tasks. And you can use all the scripts from this community. You can probably rename a virtual machine with the current date and time from the Vmware VIPerl Toolkit. But I don't use that toolkit so I don't know how to do that.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
valot
Enthusiast
Enthusiast

I  use ESX3.5 and VC2.5.

I didn't find any install for PowerCLI with this level...

0 Kudos
RvdNieuwendijk
Leadership
Leadership

PowerCLI 4.1U1, the current version, works perfect with ESX 3.5 and VC 2.5. Only the features new to vSphere will not be supported. E.g. host profiles.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
valot
Enthusiast
Enthusiast

Ok I'm trying to use the PowerCLI.

What's the sentence to rename the virtual machine as MyVm to MyVM-datetime ?

And could you gieve me an example of batch file to execute as scheduled task, I need to be connected to the vc before, etc ....???

Tks for your help

0 Kudos
RvdNieuwendijk
Leadership
Leadership

The PowerCLI commands to rename virtual machine MyVM to MyVM-DateTime are:

$DateTime = Get-Date
Get-Vm MyVM | Set-VM -Name "MyVM-$DateTime" -Confirm:$false

To run the PowerCLI rename virtual machine script as a scheduled task I would create a .cmd file with the following content:

%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" -command "&{c:\Rename-VM.ps1}" > Rename-VM.log 2> Rename-VM-error.log


The file c:\Rename-VM.ps1 should contain:

Connect-VIserver YourvCenterServerName 

$DateTime = Get-Date
Get-Vm MyVM | Set-VM -Name "MyVM-$DateTime" -Confirm:$false

Disconnect-VIServer -Confirm:$false

You can run the .cmd file as a scheduled task with a service account that has sufficient rights at the vCenter Server to rename the virtual machine.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
valot
Enthusiast
Enthusiast

Tks a lot man,

Sorry I'm on a lot other stuff...

I will test this asap and let you know.

bye

0 Kudos
valot
Enthusiast
Enthusiast

Tks a lot for your help.

All works perfectly

best regards.

0 Kudos