dnxcoded
Contributor
Contributor

Get-HardDisks - datastore to Storage Migrate disks between datastores

Jump to solution

Hi all,


Our current storage configuration having purpose built split-role bases Datastores (OS, SQL LOG, SQL DATA, APP, Exchange roles, etc.)  I am doing a storage tidy up on my VMware Infrastructure and was hoping to target just the disks of the VMs that are on any Datastore and migrate them over to another.  Rather new to to PowerCli so wondering why the command bellow does not work and reports that the file is locked.


get-harddisk -datastore "Datastore01" | Move-HardDisk -Datastore Datastore02

Would it be as the VM itself is not made aware of the command?  Would I need to enumarte the VMs on the Datastore first and then target the disks each one has and pipe it to the Move-HardDisk command?

thanks in advance

1 Solution

Accepted Solutions
Craig_Baltzer
Expert
Expert

Yes, you're bumping into the command sequence trying to move a file on the datastore without referencing the VM. Depending on the state of the VM (powered on or not) different things happen

  • VM Powered Off - The disk is moved and the VM is broken (the vmx file will still point to the original location for the HD which is no longer there)
  • VM Powered On - The disk is locked so it cannot be moved (the error you saw)

One other thing to keep in mind is that the VM configuration is also on a datastore, so if you want to move the entire VM you can't just move the hard disks

If all VMs on a datastore have all their HDs on that datastore then you can do something like

Get-VM -Datastore "Datastore01" | Move-VM -Datastore "Datastore02"

To move the VM configuration as well as its disks. If you have VMs where the disks within a single VM then you'll have a bit more work to do to sort out the disks that should be moved

Get-VM -Datastore "Datastore01" | Get-Harddisk | Where-Object {$_.FileName.Contains("[Datastore01]")} | Move-HardDisk -Datastore "Datastore02"


This finds all the VMs with one component (hard disk or configuration) on Datastore1, then for each VM finds all the hard disks that are on Datastore01 and moves them to Datastore02

View solution in original post

2 Replies
Craig_Baltzer
Expert
Expert

Yes, you're bumping into the command sequence trying to move a file on the datastore without referencing the VM. Depending on the state of the VM (powered on or not) different things happen

  • VM Powered Off - The disk is moved and the VM is broken (the vmx file will still point to the original location for the HD which is no longer there)
  • VM Powered On - The disk is locked so it cannot be moved (the error you saw)

One other thing to keep in mind is that the VM configuration is also on a datastore, so if you want to move the entire VM you can't just move the hard disks

If all VMs on a datastore have all their HDs on that datastore then you can do something like

Get-VM -Datastore "Datastore01" | Move-VM -Datastore "Datastore02"

To move the VM configuration as well as its disks. If you have VMs where the disks within a single VM then you'll have a bit more work to do to sort out the disks that should be moved

Get-VM -Datastore "Datastore01" | Get-Harddisk | Where-Object {$_.FileName.Contains("[Datastore01]")} | Move-HardDisk -Datastore "Datastore02"


This finds all the VMs with one component (hard disk or configuration) on Datastore1, then for each VM finds all the hard disks that are on Datastore01 and moves them to Datastore02

dnxcoded
Contributor
Contributor

Thank you Craig,

I am unable to try this out until on Monday but I can´t wait.

I will report back here

0 Kudos