Migrating Virtual Machine Storage

All storage for virtual machines on a specific disk can be moved with a single line of PowerShell.

John Savill

April 19, 2013

1 Min Read
Migrating Virtual Machine Storage

Q: How can I migrate all storage for virtual machines using a specific disk?

A: The command below moves the storage of all virtual machines (VMs) using the specific disk to the new location in a subfolder named for the VM. In the example I use the -WhatIf switch so no migration will actually be performed.

Use this first to confirm the actions that will be taken, then run the command without -WhatIf to actually perform the migration.

In the example below, all VMs on the E drive are moved to D virtuals. For example, a VM named savdalcm01 would be moved to a folder D:virtualssavdalvm01.

Get-VM | Get-VMHardDiskDrive | where {$_.Path.StartsWith("E:")} | ForEach-Object {Move-VMStorage -VMName $_.VMName -DestinationStoragePath ("D:virtuals"+$_.VMName) -WhatIf}

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like