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.
Tags: VMware
Similar Questions
-
Problem with VMTools &; backup of virtual machines
Hello
I can't back up some virtual machines with installed VMTools. Once I have remove VMTools machine virtual back ok.
I get the error message is as follows for virtual machines with VMTools installed:
e000954c - an error occurred while executing the command "vcbMounter" of VMware to save a virtual machine. See the backlog for more details.
I use VCB 1.5 update 2 & Backup Exec 12.5.
I tried uninstalling VMTools & reinstall but no joy yet!
Any ideas?
Thank you as always.
P
Have you tried to disable the SYNCHRONIZATION driver in just by using VSS and VMware tools or vice versa?
How do you do that?
The installation of VMware tools on a virtual machine and choose the option 'Interactive '. Choose the option "Edit", and then expand the section "VMware device drivers. On the Windows Server 2008, simply look for the "Volume Shadow Copy Service Support" option. On the Windows 2003 server, locate the VSS and the SYNCHRONIZATION options or file system synchronization driver.
-
Problem is when I vMotion virtual machine running it stop responding for 5-10 sec.
I get a black screen with the message "waiting for connection" and complete the wheel which revolves around 5-10 seconds until the display returns and vMotion. vMotion drop the ping package on the virtual computer to 78%
I created the test of setting up a pilot project of HA/DRS in my company. But I found that there is a problem with vmotion on running virtual machine.
I have 2 Dell Power Edge 2950 servers with 8 GB of RAM and dual NIC. I gave a separate connection to port vKernal for vMotion. Everything works well except vMotion.
I took RDP to the manual migration of vm and VM stop giving response for 5-10 seconds
Cool is...
-
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.
-
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
-
Problem with script on the master page
So I have my build script of the unique number bit that I have posted here before... it's on the Initialize event of the field.
If (this.rawValue == null) {}
var d = new Date();
this.rawValue = parseInt(d / 1000);
}
else {}
this.rawValue = rawValue;
}Which works very well if on the body of the form, but if I put it on the master page it re - initializes (and changes the number) whenever a subform gets shown/hidden. No idea how to stop it from doing this? I tried it on a few other events without a bit of luck.
I came across another problem with this script, a field called 'Date' was interfering with the script - throw an error "the Date is not a constructor. Is - this normal (function/field collision)?
Hi Jono,
I had problems with script within the Master pages before. What I've done in the past, it is a textfield hidden in the main pages of script with overall binding (which featured many here today); then same name textfield in the master page picks it up.
Good luck
N.
Post edited by: Niall O'Donovan
-
Hi all
I checked a few posts on the migration to the new vCenter Server virtual machine. But I'm not very good with Powercli and need some help here.
We have a new vCenter server where we migrate virtual machines from one source vCenter server. Here are two things that I don't know how to connect together to make sure that bwfore we turn on the virtual machine to the virtual machine is connected to its source network.
Part 1 - this script works well but do not get any network on the vCenter destination.
cluster = Get-Cluster "clusterA.
$inventory = get-Cluster $cluster | Get - VM | Add-Member - MemberType ScriptProperty-name "VMXPath" - value {$this.extensiondata.config.files.vmpathname}-Passthru-Force | Select-Object Name ResourcePool, folder, VMXPath |
$inventory | Export-Csv c:\file.csv
$inventory = import-csv c:\file.csv
$cluster = get-group 'b '.
{foreach ($vm to $inventory)
$ESXHost = get-Cluster $cluster | Get-VMHost | Select - 1 first
New-VM - VMFilePath $vm. VMXPath - VMHost $ESXHost - location $vm. Folder - ResourcePool (Get-Cluster $cluster |) Get-ResourcePool $vm. ResourcePool)
}
Part 2 - I want to preserve the Portgroup macaddress and the Ip of the virtual computers and connect them to the new vCenter. How can I do this with the script below. Or how can I combine them together?
$vm_list = get-Cluster-name "clustera | Get - VM test * | Name sort
$information = {foreach ($vm to $vm_list)
$network_adapter_information = get-NetworkAdapter - VM $vm
$vm | Select Name,PowerState,ResourcePool,@{N="Path; E= {$_. ExtensionData.Summary.Config.VmPathName}},@{N="NetworkAdapter '; E = {[string]: join (":", ($network_adapter_information |))} %{$_. {{(Nom + "," + _.NetworkName $}))}}, @{N = "MacAddress"; E = {[string]: join (",", ($network_adapter_information | % {$_.}))} MacAddress}))}}
}
Step 2
# Unsubscribe virtual machines
Remove-VM - VM $vm_list-RunAsync Verbose - confirm: $false
Step 3
$cluster = get-group 'b '.
{foreach ($vm to $inventory)
$ESXHost = get-Cluster $cluster | Get-VMHost | Select - 1 first
New-VM - VMFilePath $vm. VMXPath - VMHost $ESXHost - location $vm. Folder - ResourcePool (Get-Cluster $cluster |) Get-ResourcePool $vm. ResourcePool)
}
# Save virtual machines
foreach ($info in $information)
{
$vmxpath = $info. Path
$resource_pool = $info. ResourcePool.Name
New-VM - ResourcePool (ResourcePool-Get-name $resource_pool) VMFilePath - $vmxpath - RunAsync-Verbose | Out-Null
}
Step 4
# Put the network cards
foreach ($info in $inventory)
{
foreach ($network_information in ($info.NetworkAdapter - split ":"))))
{
$virtual_machine = $info | %{$_. Name}
$network_adapter = ($network_information-split ",") [0]
$network_vlan = ($network_information-split ",") [1]
Get-VM-name $virtual_machine | Get-NetworkAdapter-name $network_adapter | Together-NetworkAdapter - NetworkName $network_vlan-Verbose-RunAsync-confirm: $false | Out-Null
}
}
# Start the virtual machines
foreach ($vm to $vm_list)
{
Start-VM - VM $vm. Name-RunAsync Verbose - confirm: $false | Out-Null}
}
Thanks in advance for any help.
Hi all
I made some changes to the script and it worked for me. We have added a host on the destination with all exchanges and storage mapped vCenter.
$vm_list = get-Cluster-name 'Site B - b | Get - VM | Name sort
$information = {foreach ($vm to $vm_list)
$network_adapter_information = get-NetworkAdapter - VM $vm
$vm | Select Name,PowerState,ResourcePool,@{N="Path; E= {$_. ExtensionData.Summary.Config.VmPathName}},@{N="NetworkAdapter '; E = {[string]: join (":", ($network_adapter_information |))} %{$_. {{(Nom + "," + _.NetworkName $}))}}, @{N = "MacAddress"; E = {[string]: join (",", ($network_adapter_information | % {$_.}))} MacAddress}))}}
}
# Unsubscribe virtual machines
Remove-VM - VM $vm_list-Verbose - confirm: $false
$cluster = get-Cluster "Site A - clustera.
{foreach ($vm to $information)
$ESXHost = get-Cluster $cluster | Get-VMHost | Select - 1 first
New-VM - VMFilePath $vm.path - VMHost $ESXHost - location $vm. Folder - ResourcePool (Get-Cluster $cluster |) Get-ResourcePool $vm. ResourcePool)
}
# Save virtual machines
foreach ($info in $information)
{
$vmxpath = $info. Path
$resource_pool = $info. ResourcePool
New-VM - ResourcePool (ResourcePool-Get-name "test1") VMFilePath - $vmxpath - RunAsync-Verbose | Out-Null
}
# Put the network cards
.
foreach ($info in $information)
{
foreach ($network_information in ($info.NetworkAdapter - split ":"))))
{
$virtual_machine = $info | %{$_. Name}
$network_adapter = ($network_information-split ",") [0]
$network_vlan = ($network_information-split ",") [1]
Get-VM-name $virtual_machine | Get-NetworkAdapter-name $network_adapter | Together-NetworkAdapter - NetworkName $network_vlan-Verbose - confirm: $false | Out-Null
}
}
# Start the virtual machines
foreach ($vm to $vm_list)
{
Start-VM - VM $vm. Name-RunAsync Verbose - confirm: $false | Out-Null
}
Hope this will help many of you.
-
Problem of migration of a virtual machine with multiple vCPUs
When I try to migrate some of our virtual machines with vMotion, I get the following error.
«Impossible to migrate from host a to host b: virtual machine has 4 virtual CPUs, but the host only supports 1.» The number of virtual processors can be limited by the selected guest OS for the virtual machine or the granting of licenses for the host".
The two ESX Server are identical HP DL380 with two quad core Intel Xeon. They are both connected to the same server vCenter (2.5). They both use the same license server. And, the VM OS is set to Windows Server 2003 Enterprise (32-bit), which is responsible for 4 vCPUs (it does now after all).
I tried moved under voltage power VM off and got the same error, so I changed the vCPU to 1 and it migrated correctly. Then, I changed it to 4 vCPUs with no problems on the new host. Only problem is, I can't stop some of the virtual machines to migrate to the new host because of the availability requirements.
~ Brian
Have you tried to change the settings of your license and apply them, just in case where? I had the weird services fails when there is a kind of latency hit the license of the ESX host server.
-KjB
VMware vExpert
-
Clone virtual machine configuration
Hello
I have a requirement to clone a single copy of the configuration of the VM in a datacenter to another data center.
We essentially use HUR to do a replication of the storage of a domain controller to another. Once replication is complete and has been shared, we climb the target LUN with Signature data warehouses are ' option and the same data store name. With that, most disk mappings is lost in particular on the virtual machines with large number of disks and we eventually remove these drives and do a manual mapping with the same SCSI controller than source VM.
My requirement is I want to automate this process and for which I need to capture details first source below and then reproduce the same destination VM.
Source VM
VMDK path with data store name
VMDK mapping to each scsi controller.
The VMDK disk size
Mappings of RDM
SCSI controller shares (if any)
With the above information, I am looking for script map VMDK disks with the same data store name and the same number of SCSI controller to destination.
If someone could help me, that would be great and I will save a lot of time spent on manual mapping.
Thanks in advance.
The following script to retrieve the info you would need for step 1.
Get - VM | Get-hard drive |
Select @{N = "VM"; E={$_. Parent.Name}},
Name,CapacityGB,filename,@{N='Datastore'; E={$_. FileName.Split(']') [0]. TrimStart('[')}},
@{N = "SCSIid"; E = {"{0} ': {1}" f (& {$script: ctrl = Get-controller SCSI - HDD $_;}) "} $script: ctrl. ExtensionData.BusNumber}), $_. ExtensionData.UnitNumber}},
@{N = "Shared SCSI"; E = {$script: ctrl.} BusSharingMode}},
@{N = "RDM"; E = {if($_.) DiskType - match 'Physical') {$_.} ScsiCanonicalName}}}
-
New computer with Windows in a Virtual Machine installation
Hello
I want to do a clean install on my new computer, so I can run Linux as main OS with Windows 7 on a virtual machine using VirtualBox.
Is it possible/legal? How can I activate windows?
EDIT: I forgot to mention that I have an OEM windows license.
See you soon / Erik
Yes, the end-user Windows 7 license contract permits.
2. INSTALLATION AND USE RIGHTS.
a. one copy per computer. You can install one copy of the software on a single computer. This computer is "licensed computer.
b. a computer license. You can use the software on up to two processors of the computer under license at some point. Except as provided in these license terms, you cannot use the software on any other computer.
c. number of users. Except as provided in these license terms, only one user may use the software at a time.
d. other Versions. The software may include several versions, such as 32-bit and 64-bit. You may install and use only one version at a time.
d. use with Virtualization Technologies. Rather than use the software directly on the licensed computer, you can install and use the software within the single virtual (or emulated) system on the licensed computer. When used in a virtualized environment, content protected by digital rights management technology, BitLocker or any hard drive full-volume encryption technology is perhaps not as secure as protected content not in a virtualized environment. You must comply with all national and international laws that apply to such protected content.
You may need to use the activation of the phone well:
How to activate Windows 7 manually (activate by phone)
1) click Start and in the search for box type: slui.exe 4
(2) press the ENTER"" key.
(3) select your "country" in the list.
(4) choose the option "activate phone".
(5) stay on the phone (do not select/press all options) and wait for a person to help you with the activation.
(6) explain your problem clearly to the support person.
http://support.Microsoft.com/kb/950929/en-us -
Problems of migration of a virtual machine
Hello
I have a problem when you try to migrate a virtual machine to an ESXi to and another ESXi. I migrate from power off State. That's what I get:
I have 2 ESXi host with vCenter device.
When I go to the preview of the hosts, in the first (it is the destination of the migration), I have no CPU usage and memory. There is something wrong because I have the vCenter and other Linux machine powered:
The other host (this is the source of the migration) looks good:
How could I solve this problem?
I'd really appreciate your help.
Best regards.
Thanks for the reply.
I reboot the host and now I can migrate and CPU and memory info is correct.
Kind regards.
-
Impossible to clone virtual machines to VSAN datastore
Hi all
Whenever we try to clone a virtual machine using vCenter vSAN not store data to the vSAN data store fails with the following error.
File /vmfs/volumes/540024e7-2d8bb59e-0bef-40a8f0305c2c/blr7-dhcp-1/***.vmdk not found.
It is a cluster of vSAN 3 node with 1 * 2 SSD * magnetic disk by the configuration of the node.
! 0 gig uplink connected to vDS with one vlan separate tag group of ports (Distributed Switch). Multicast IGMP snooping is enabled on the VIRTUAL LAN that is used for the VTEP.
Storage strategy is: tolerate 1, band 3, 70% cache read
Storage strategy using 3-band
Cluster shows also in good health
~ # esxcli vsan cluster get
Cluster information
Enabled: true
Current local time: 2015-01 - 05 T 14: 33:05Z
Local node UUID: 54a7b9fa-afde-3f59-1d67-40a8f0305c2c
State of the local node: BACKUP
Health status of local node: HEALTHY
Cluster under master UUID: 53e07d1e-4154-1e32-1cc6-40a8f0305c68
Cluster under backup UUID: 54a7b9fa-afde-3f59-1d67-40a8f0305c2c
Cluster under UUID: 5276ec11-3024-d7e5-6696-cb2b47017814
Cluster under membership entry revision: 2
Subgroup Member UUID: 53e07d1e-4154-1e32-1cc6-40a8f0305c68, 54a7b9fa-afde-3f59-1 d 67-40a8f0305c2c, 54a6abf6-9350-0741-2815-40a8f030f494
Under Cluster Membership UUID: 9f6eaa54-5573-d61e-d26f-40a8f0305c68
~ network vsan # esxcli list
Interface
VmkNic name: vmk3
IP Protocol: IPv4
Interface UUID: 1f6ca254-337e-9641-1c50-40a8f0305c68
Agent group multicast address: 224.2.3.4
Agent Group Multicast Port: 23451
Multicast Address Group Master: 224.1.2.3
Master Group Multicast Port: 12345
Multicast TTL: 5
~ # esxcli network ip connection list | egrep 224
UDP 0 0 224.1.2.3:12345 0.0.0.0:0 34586 worker spend
UDP 0 0 224.2.3.4:23451 0.0.0.0:0 34586 worker spend
Also the deployment of the virtual machine to vSAN datastore also very slow.
Could you please help me understand the issue.with cloning.
With respect,
Aju
This post should help determine the number of hosts.
VSAN part 25 - hosts much-needed to tolerate failures? CormacHogan.com
The number of disks is harder once you start adding bandwidth, because you also have to take into components witness account.
Each band will require a disc, and you increase FTT, you will need to double the number of disks you want to mirror any of the components score. And then, of course, welcome the witnesses.
-
Run the script inside the virtual machine the user when the user connects or reconnects
Hello
is it possible to detect the user that the user has connected or reconnected to his office inside the virtual machine and run a script?
It is also possible within the VM user to determine if the user is connected and how long?
One way to do this is via the following powershell command, but this only works if the user is connected through PCoIP Protocol.
Get-WmiObject-class Win32_PerfRawData_TeradiciPerf_PCoIPSessionGeneralStatistics - SessionDurationSeconds property
Best regards
> it is possible to detect the user that the user has connected either reconnected to his office inside the virtual machine and run a script?
You can run scripts as user on login and reconnect, this has been a feature since 3.0. See running commands on the desktop view.
> It is possible inside the VM user to determine if the user is connected and how long?
I don't think that we expose, but you should be able to query Windows for the connection time, or you could write the last time to connect with a script (maybe that is the reason for your first question?).
Mike
-
Is no vmdk file, but the script says, all virtual machines backed up Ok!
Hello everyone;
Please excuse any lack of details because this is the first time that I write. I've scoured internet for days now trying to find no matter how much detail that could help me solve the problem. I'm new in the world of script ESXi and ghettoVCB.
My intention is to run several tasks on a schedule. Each type of backup (quarterly, monthly, weekly, daily and multiple) runs at a specific time. The planning section works very well.
I'm hoping to solve this urgent backup, I should be able to solve reboot.
Here is the command I use:
/vmfs/volumes/datastore1/ghettoVCB.sh w /tmp/ghettoVCB-work.multiple f/vmfs/volumes/datastore1/vmlist-Multiple g/vmfs/volumes/datastore1/vmconfig-DataSet1-multiple-l /vmfs/volumes/datastore1/ghettoVCB_logs/ghettoVCB.Multiple_Backup.logvmconfig-DataSet1-multiple contains:
# Multiple backups - rotation County 6
#
VM_BACKUP_VOLUME = / vmfs/volumes/Vault2-DataSet1/URANUS/Multiple
DISK_BACKUP_FORMAT = thin
VM_BACKUP_ROTATION_COUNT = 6
POWER_VM_DOWN_BEFORE_BACKUP = 0
ENABLE_HARD_POWER_OFF = 0
ITER_TO_WAIT_SHUTDOWN = 4
POWER_DOWN_TIMEOUT = 5
SNAPSHOT_TIMEOUT = 15
ENABLE_COMPRESSION = 0
VM_SNAPSHOT_MEMORY = 0
VM_SNAPSHOT_QUIESCE = 0
VMDK_FILES_TO_BACKUP =
Vmlist-multiple contains 1 server is listed:
# List all virtual machines that are backed up several times a day
HEAT
The log indicates that the backup was successful - but it has not been the case. Backup size should be approximately 8 GB. However, when you look at the output folder, only the following files are here:
HEAT.vmx
STATUS.ok
Question is now - where are the vmdk files that should be present?
Output (-d debug) can be found here: http://pastebin.com/hMGphTL3
So, here is what I observed:
When you run the script, the snapshot only takes a few seconds to create and delete then. I'm seeing happens on the list of the tasks of vSphere Rencent (screenshot attached).
If I create a snapshot manually - it will take much more time to create and delete a snapshot. The difference here is 6 minutes, and 4 seconds using the script create a snapshot manually.
So my presumption is that he is not actually create the snapshot, although vSphere said it is being created. So why is it the case?
Help, please.
ADDENDUM:
If I run the following:
./ghettoVCB.sh m HEAT
The backup is successful.
Your said he clearly did not config file to back up all files hard.
VMDK_FILES_TO_BACKUP =
I expect to see something like this if you want all the hard files
VMDK_FILES_TO_BACKUP = "all".
-
Problem with the backup computer virtual to Virtual Center 4 with VDR
VC in Vsphere4 is the virtual machine. When I try it with VDR save there is an error failed to create a snapshoot because the operation has timed out.
VC is Windows 2003 Standardx64.
I know the problem with vdr and VSS service and so on, but I does not do so in this situation.
All reviews are useful.
Thank you.
Thank you
What about the vssadmin list providers?
Maybe you are looking for
-
This #^ $% * & ^ outfit has changed the size of USB plug on the Zip which was used on the Video & Clip + with no warning. I need a USB cable that is longer than that provided with the Zip file. It is no longer a mini 'A '. It is too big to be 'micro
-
I found a question similar to this but need more specific assistance. As I turned on my computer, a window pops up saying "the entry point of procedure not found in the library of dynamic links SHLWAPI.dll." This message has not left since and my co
-
Hi all I need to test the memory usage of the application that I'm developing. Can someone please suggest a tool? Thank you much in advance.
-
BlackBerry Smartphones plate fragile plastic under the space bar
Hi all! I just bought the Bold 2 (9700), and I find that the plastic plate just below the SPACEBAR (between the spacer bar and chromium) goes up and down like a coward. When I type and press the space bar or any key in the last line, the plate moves
-
I have an old hard drive with Windows 8. How can I remove Windows using the drive as an external drive? I don't have the laptop.