Add copied hard disk (VMDK) on a virtual machine

I'm new to PowerCLI and can't seem to find information on this "new" process

I'm looking to automate the addition of a cloned hard disk (VMDK) VM (1) to an another VM (2) existing.  I figured out how "Hard drive copy" VM1 VM2 data store, but can't the formula to VM2.

To copy the disc, I use the following command:

$vm1 = "name of vm1.

$vm2 = "name ofthe virtual machine 2 .

$ds = "datastor" e

Get-disk hard - VM $vm1 | Where {$_.} CapacityGB - lt 10} | Copy-hard drive - DestinationPath ' [$ds] vm2 $/ $vm2 - 2.vmdk '-Force

In fact, here is what it looks like:

Get-disk hard - VM System1. Where {$_.} CapacityGB - lt 10} | Copy-hard drive - DestinationPath "[NFS2] System2/System2 - 2.vmdk '-Force

MISTLETOE we do today via vCenter is - change the s parameter > Hardware tab > Add > hard drive > use an existing virtual disk > Browse > check the virtual device node (SCSI 0: (x) - and it works.)  I can start VM2 and the Windows operating system works very well and everyone is happy.

To set the hard drive via PowerCLI, I use the following command:

New-disk-hard - VM $vm2 - DiskPath "[$ds] $vm2/vm2 $-2.vmdk»

In fact, here is what it looks like:

New- hard drive - VM System2 - DiskPath ' [NFS2] System2/System2-2.vmdk '

When I run the command, I see vCenter 'work' and then error with Incompatible device support specified for the device '0'.  I have ready many forums reporting the error when you perform a RDM or tries to add a secondary SCSI controller, I don't want to do.

A few things to note:

Must be on the default 0 (Virtual LSI Logic SAS) SCSI controller

Virtual device node must be SCSI 0:2 (it would be a third drive on the system)

The data store is a different data store that the other disks attached to VM2 (discs 1 and 2 are on NFS1, new drive would be on NFS2).

When I first copy the disc, it indicates the persistence as unknown, do not know if this is a factor. Any help would be appreciated.

ESXi, 5.0 Update 1 (5.0.0,821926)

PowerCLI 5.5 Release 2

Thank you

SC

Lol, I'll type slowly

No, I'm afraid that we cannot change the API, or the coding behind the cmdlet.

But we can call the APIs directly from PowerCLI, something like this for example

function add-HD {  param($VMname, $Filename, $Controller)

  $dsName = $Filename.Split(']')[0].TrimStart('[')

  $vm = (Get-VM $VMname).ExtensionData  $ds = (Get-Datastore -Name $dsName).ExtensionData

  foreach($dev in $vm.config.hardware.device){    if ($dev.deviceInfo.label -eq $Controller){      $CntrlKey = $dev.key    }  }  $Unitnumber = 0  $DevKey = 0

  foreach($dev in $vm.config.hardware.device){    if ($dev.controllerKey -eq $CntrlKey){      if ($dev.Unitnumber -gt $Unitnumber){$Unitnumber = $dev.Unitnumber}      if ($dev.key -gt $DevKey) {$DevKey = $dev.key}    }  }

  $spec = New-Object VMware.Vim.VirtualMachineConfigSpec  $spec.deviceChange = @()  $spec.deviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec  $spec.deviceChange[0].device = New-Object VMware.Vim.VirtualDisk  $spec.deviceChange[0].device.backing = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo  $spec.deviceChange[0].device.backing.datastore = $ds.MoRef  $spec.deviceChange[0].device.backing.fileName = $Filename  $spec.deviceChange[0].device.backing.diskMode = "independent_persistent"  $spec.deviceChange[0].device.key = $DevKey + 1  ## The UnitNUmber SCSIID 7 is reserved for the Controller - so ignore it and skip to 8.  if ($Unitnumber -eq 6) {$Unitnumber = $Unitnumber + 1}  $spec.deviceChange[0].device.unitnumber = $Unitnumber + 1  $spec.deviceChange[0].device.controllerKey = $CntrlKey  $spec.deviceChange[0].operation = "add"  $vm.ReconfigVM_Task($spec)}

Add-HD -VMname "System2" -FileName "[NFS2] System2/System2-2.vmdk" -Controller "SCSI Controller 0"

I created a function called Add - HD, which will do more or less the same thing, just as the cmdlet New-hard drive when it is used with the name parameter file, but instead to call the cmdlet, the function calls the API ReconfigVM_Task directly.

The downside of this is that we will have to compile the parameter passed to this method.

In fact, most of the PowerCLI cmdlets do exactly the same thing, they call the API methods.

You can view these calls when you draw a cmdlet with the tool of Onyx .

Tags: VMware

Similar Questions

  • Add a virtual disk to an existing virtual machine.

    Hello

    Anyone know what would be the best way to create an action to add a new virtual disk (hard) to an existing virtual computer? I have found no existing action/workflow, and I do not know where to start.

    Thank you

    Hey Mikael,.

    There is a "workflow" for this!

    Library / vCenter / Virtual Machine Management / management of devices / add a disk.

    This workflow, you can add a VMDK to a virtual machine.

  • HOWTO delete a VMDK to a virtual machine without actually deleting the vmdk disk file?

    How to remove a file VMDK to a virtual machine without actually deleting the vmdk disk file?

    Details:

    My perl script, I need to temporarily remove a vmdk to a virtual machine file. However I do not want the vmdk file should be removed from the virtual machine. For example, the gui vsphere provides this option to delete a virtual disk without deleting the virtual disk from the disk files.

    In my script, I use the ReconfigVM_Task to do this. This does the job, but also removes the vmdk file. How can ensure me that the vmdk file will not delete the disk?

    The code snippet is something are:

    My $devspec = VirtualDeviceConfigSpec-> new)

    device = > $device,

    #device to delete above:

    operation = > VirtualDeviceConfigSpecOperation-> new ('remove'));

    Push (@$ devspec_list, $devspec);

    My $config_spec = VirtualMachineConfigSpec-> new)

    deviceChange = > $devspec_list

    );

    my $task = $template_view-> ReconfigVM_Task (spec = > $config_spec);

    would really appreciate your help

    s

    Take a look at this script: vmdkManagement.pl

    =========================================================================

    William Lam

    VMware vExpert 2009

    Scripts for VMware ESX/ESXi and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

    Twitter: @lamw

    repository scripts vGhetto

    Introduction to the vMA (tips/tricks)

    Getting started with vSphere SDK for Perl

    VMware Code Central - Scripts/code samples for developers and administrators

    VMware developer community

    If you find this information useful, please give points to "correct" or "useful".

  • VMware Workstation is unable to open one of the virtual disks required by this virtual machine because it is larger than the maximum file size supported by the host file system.

    I'm transitioning from Windows XP (64-bit) on a new computer with Windows 7 installed.  I undertook to VMWare Workstation 6 7.0.1 in the process.  The problem is with a very large RAID 5 volume on the new system.  It's a score of 5.45 TB (TPG and NTFS).

    When I try to start a virtual machine on this volume, I get the message "VMware Workstation cannot open one of the virtual disks required by this virtual machine because it is larger than the maximum size of the files supported by the host file system.".  This is obviously not true.  If I copy the virtual machine to another drive on the system, it starts without a problem.

    Anyone have any ideas on how to work around this problem?

    try to add this line in the vmx file:

    diskLib.sparseMaxFileSizeCheck = "false".

    Maybe it helps.

    VMDK-type do you use?

    monolithicSparse? -C' is the only part type more?

    ___________________________________

    VMX-settings- Workstation FAQ -[MOA-liveCD | http://sanbarrow.com/moa241.html]- VM-infirmary

  • Error: "VMware Workstation has suspended this virtual machine because the disk on which the virtual machine is stored is almost full."

    I get this error message:

    VMware Workstation has suspended this virtual machine because the disk on which the virtual machine is stored is almost full. To continue, free 1.3 GB of additional disk space.

    I read up on the subject and found that I have to re size a partition. Anyone know what it could be? I can't find anything that looks like it has something to do with VMware. Does anyone know what size and what file system is it?

    My OS:
    Tumbleweed OpenSUSE x 64

    Thanks in advance

    On more creative, my home and root file systems were not extended to my full disk space :^)

  • Add physical disk to disk attached in ESXi virtual machine

    Hi friends,

    I would have attached physical disk to the virtual machine, I explain:

    I have a freenas VM create in ESXi 5.5 but I want to add a new hard drive, this hard drive is a physical, fixed equipment in my 5.5 ESXi, possible? If Yes, how?

    After I want to mount iSCSI in freenas and I'll make backups

    Thank you very much

    Rapici

    Hi brunofernandez1

    very thanks for the doc, I'll try Raw Device Mapping and explain

    Thank you very much

    Rapici

  • Add additional hard disk to ESX4.1

    Hello

    I have a box of esx with 500 GB hard drive, I use this to objective test and have 5-6 vm on local storage. Now, I would like a few more storage and plans to add another hard drive to ESX box for making fewer virtual machines. I've not done this before so would like to know if I add an additional hard drive, I'll be able to create another customer vspehere data store? If this is not the case, how can I use the extra space on it?

    Thank you...

    Yes, if the drive is connected to a supported disk controller, t appear in the vSphere Client. What does the Wizard "add storage", it creates a new partition on the drive and it is shaped with the VMFS file system.

    André

  • I can add a hard disk in-house Satellite A300 - 20 p

    Satellite a300 20 p has 2 slots for HDD
    Can I add another next to the existing one?

    Hello

    You can check it out yourself.
    There should be a second HARD drive Bay.
    Remove the second HDD Bay cover and check if there is a disk (PIN) connector.
    If you find not all connectors so that would mean that a second HARD disk controller is not available and the 2nd HARD drive usage is not possible.

    See you soon

  • How can I add a hard disk WIN98 in my HP WINDOWS XP (as master and slave, or drive C:\ & D:\?)

    How to install a hard drive that came out a WIN98 and install it in a HP Compaq Home Edition. (Master and slave OR C:\  D:\ ?)

    Thank you please

    George

    Hello

    1. you are trying to attach an internal hard drive?

    You may need to contact the device manufacturer for more information on the physical connection and the BIOS (Basic input output) configuration when you fix the hard disk.

    Note:

    BIOS change / oxide of additional metal (CMOS) semiconductor parameters incorrectly can causeserious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the configuration of the BIOS/CMOS settings can be solved. Changes to settings are at your own risk.

    Once you configure the hard drive in the BIOS, you can consult the links below for more information about how to partition and format a hard disk using the Windows XP Setup program

    http://support.Microsoft.com/kb/313348

    See also:

    How to change drive letter assignments in Windows XP

    http://support.Microsoft.com/kb/307844

  • Please help - I need to add more hard disk space (I know, I screwed up in the beginning!)

    I use VMWare fusion (1.1.3) on a mac intel, and I'm running a windows xp virtual machine. I had no plan to install all programs on it, just wanted to test Web sites, but now I need to intsaller office and do not have enough disk space. Is it true that you have to use third party software to do this? Can someone please? Thank you!

    Take a look at: resizing of the ramdisks with step by step Instructions

    Also because your using the Fusion 1, you can also watch: resize virtual disk for Windows guests with step by step Instructions

  • Import hard file to the new virtual machine

    Hello all-

    I'm trying desperately to VMWare server 2 on the figure, but can't.  I tried to get 2 virtual disks (2 files, hard)

    imported in VMWARE Server.  When I go to create the virtual machine, I specify that I want to use an existing hard drive.

    I then click on browse, and the only thing that appears is the "data store".  I have converted files, sitting in a folder on my desktop a goner

    and I can't navigate there.

    What Miss me?

    Thank you!

    Mike

    Hello

    You can:

    1. create the new data store for your vmdk files (you can provide full path for these files)

    2. you can copy the vmdk files in your data store existed.

    Add datastore - Web Interface full skylight - command-> add the data store

    J.

    If you have found this device or any other answer useful please consider the use of buttons useful or Correct to award points.

  • How to extend vmdk for several virtual machines?

    Hello!

    I have a 300 + vm on vsphere5.1 and I need to extend the system drive on each of them. Have ideas of how do with powercli? Thank you.

    You can try something like that.

    It will increase the size of 20% vmdk. Note that the virtual computer must be turned off for this.

    Get-VM | Where {$_.PowerState -eq "PoweredOff"} |Get-HardDisk -Name "Hard disk 1" |Set-HardDisk -CapacityGB ([int]($_.CapacityGB * 0.2)) -Confirm:$false -HelperVM $vm
    

    You can find another example in need a script powercli to increase Harddisk1 of virtual machines in a 20 GB file, can anyone give a script.

  • Edit a VMDK with another virtual machine snapshots?

    I have a virtual machine that has snapshots 4. I want to temporarily detach the boot drive, attach it to a different VM, extend the partition and finally relate to the original virtual machine. Can I attach the original VMDK file, or can I join < name > VM - 00000X.vmdk file?

    You just want to change the size of the partition you want to resize the virtual disks?

    In case you want to resize the virtual disks, you must not have any instant assets! In case you just want to change the partition structure in a virtual disk without changing its size, then use the snapshot active (the last one in the chain).

    Always keep in mind that snapshots are used as a chain, each link in the chain is active!

    André

  • Windows 2000 Pro system/disk physical conversion into virtual machine

    Fairly new to the world of the VM and was directed to VMWare for possibly a problem for us.

    We have a gentleman with an older system running Windows 2000 Pro (SP4) with a ton of software installed.  We put in place a new Win7 Pro system for him, but he won't Cross and reinstall everything (in addition to the time involved, some of the software is older and Win7 compatibility is probably a problem).

    We were originally at a switch KVM allows you to switch between systems, but then I found in the converter and thought this would be a great solution for him.  My thoughts are to use the converter to create a virtual machine from its old system/hard drive and install Player on its new Win7 system, it can fire up to his old Win2000 environment when he needs to work - and we can empty the old physical system.

    I have scanned through the documentation for converter and understood that I would need a version of Converter before 4.3 (like, 4.01 or earlier?).  Now, what should I install on it have to happen?

    Do I need to set permissions on its legacy system to expose the discs on the network?

    Can I get the old HD and connect it to the new system and convert this way?

    Do I need to install something on the source and the host system to do this?

    Once I can understand this point, we may need to conduct a number of other older systems, it keeps alive for the same reasons.

    I guess I should ask first - is that what this application is designed to do?  Or it fits into another software solution?

    Thank you very much for any information/guidance someone can provide - greatly appreciated.

    (PS.  Please don't just live/link me to the documentation.  As mentioned, I went through that, and I'm not real familiar with the setting/process, so that really helped a lot.  Thank you once again.)

    VHDs are used by VirtualBox and VirtualPC
    VMware uses the vmdk files

    You start converter on the Win2000 and tell him to "convert THIS machine.
    It then creates a vmx file plus a vmdk file.

    On the Win7 host you install VMplayer or workstation, and then simply double-click the vmx file... If everything works as expected

  • resize the disk space on the virtual machine

    Hello!

    I have a small problem, when I converted a virtual machine on my esx server so I chose 14FR for the virtual machine.

    But I now realize that I need more space on the virtual machine. but the problem is that I stop the virtual machine and

    give more space but the does not get more space than any alcolated in diskmgmt. and there I have to

    make a new partition.

    Can I add a disc more on C: by do not format the drive? or can I add more disk space to a new partition

    (if I add 20 GB now and want to add 20 extra GB to the same partition in 2 months or something like that?) ??

    Thank you

    / R

    http://malaysiavm.com/blog/how-to-resize-Windows-2003-Server-virtual-disk-on-VMware-ESX/

    Here is the guide. Hope is useful.

    Craig

    vExpert 2009

    Malaysia, VMware communities - http://www.malaysiavm.com

Maybe you are looking for