I'm new to PowerCLI and can't seem to find any 'newer' information on this process.
I'm attempting to automate the adding of a cloned hard drive (VMDK) from VM(1) to another existing VM(2). I figured out how to "Copy-HardDisk" of VM1 to the datastore of VM2, but can't seem the formula to attach it to VM2.
To copy the disk, I'm using the following command:
$vm1 = "vm1 name"
$vm2 = "vm2 name"
$ds = "datastore"
Get-HardDisk -VM $vm1 | Where {$_.CapacityGB -lt 10} | Copy-HardDisk -DestinationPath "[$ds] $vm2/$vm2-2.vmdk" -Force
Here is actually what it looks like:
Get-HardDisk -VM System1 | Where {$_.CapacityGB -lt 10} | Copy-HardDisk -DestinationPath "[NFS2] System2/System2-2.vmdk" -Force
The GUI way we do this today via vCenter is - Edit Setting s > Hardware tab > Add > Hard Disk > Use an existing virtual disk > Browse > Verify the Virtual Device Node (SCSI (0:x) - and it works. I can boot VM2 and the Windows OS works fine and everyone is happy.
To attach the hard disk via PowerCLI, I'm using the following command:
New-HardDisk -VM $vm2 -DiskPath "[$ds] $vm2/$vm2-2.vmdk"
Here is actually what it looks like:
New-HardDisk -VM System2 -DiskPath "[NFS2] System2/System2-2.vmdk"
When I run the command, I see vCenter 'working' and then errors out with Incompatible device backing specified for device '0'. I've ready many forums stating the error when doing a RDM or attempting to add a secondary SCSI controller which I don't want to do.
A few things to note:
Needs to be on the default SCSI controller 0 (Virtual LSI Logic SAS)
Virtual device node needs to be SCSI 0:2 (this would be a third drive on the system)
The datastore is a different datastore than the other disks attached to VM2 (disks 1 and 2 are on NFS1, new disk would be on NFS2).
When I first copy the disk, it states the Persistence as Unknown, not sure if this is a factor. Any help would be appreciated.
ESXi, 5.0 Update 1 (5.0.0,821926)
PowerCLI 5.5 Release 2
Thanks,
SC