VMware Cloud Community
BrianGordon84
Contributor
Contributor
Jump to solution

Copy .vmdk file from one datastore to another

I need a script to be able to copy one .vmdk file from one datastore to another. I'm wanting to copy a block aligned formatted hd from a datastore to a newly created vm but I'm not wanting to do this manually everytime I create a vm. Any suggestions?

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can use the Copy-DatastoreItem cmdlet for that.

Seems I forgot about the Copy-HardDisk cmdlet.

Makes it even easier

For example:

$newLocation = "[DS2] NewFolder"
$vmName = "PC1"
Get-VM $vmName | Get-HardDisk | %{
	Copy-HardDisk -HardDisk $_ -DestinationPath $newLocation
}

This will copy all hard disks on PC1 to the new datastore.

Note that you need to be connected to an ESX(i) server, not the vCenter.

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

You can use the Copy-DatastoreItem cmdlet for that.

Seems I forgot about the Copy-HardDisk cmdlet.

Makes it even easier

For example:

$newLocation = "[DS2] NewFolder"
$vmName = "PC1"
Get-VM $vmName | Get-HardDisk | %{
	Copy-HardDisk -HardDisk $_ -DestinationPath $newLocation
}

This will copy all hard disks on PC1 to the new datastore.

Note that you need to be connected to an ESX(i) server, not the vCenter.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos