Skip to content

Instantly share code, notes, and snippets.

@mczerniawski
Last active May 14, 2018 12:17
Show Gist options
  • Select an option

  • Save mczerniawski/d7fe2d7b935ec6874639d211305b47aa to your computer and use it in GitHub Desktop.

Select an option

Save mczerniawski/d7fe2d7b935ec6874639d211305b47aa to your computer and use it in GitHub Desktop.
$cluster = 'cluster'
$HVNodesActive = Get-ClusterNode -Cluster $cluster | where {$_.State -eq 'UP'}
$AllVMs = Get-VM -ComputerName $HVNodesActive | select Name,Path,ComputerName
#region Workflow declaration
Workflow Invoke-ParallelLiveMigrateStorage
{
Param (
[parameter(Mandatory=$true)]
$VMList,
[parameter(Mandatory=$true)]
[String] $DestinationRootFolder,
[parameter(Mandatory=$true)]
[String] $Cluster
)
ForEach -Parallel ($VM in $VMList) {
$NewPath = Join-Path -Path $DestinationRootFolder -ChildPath $VM
get-clustergroup -Cluster $Cluster -Name $VM | ForEach-Object {
Move-VMStorage -DestinationStoragePath $NewPath -VMName $_.Name -ComputerName $_.OwnerNode
}
}
}
#endregion
#MOVE Storage where VMs are
$VMList = @()
foreach ($hvhost in $HVNodesActive) {
$VMList += ($AllVMs | Where-Object {"$($_.Path)" -notmatch $_.ComputerName})
}
foreach ($hvhost in $VMList) {
$VMStorageToMigrate = $VMList | Where-Object {$_.ComputerName -match $hvhost}
Invoke-ParallelLiveMigrateStorage -VMList $VMStorageToMigrate -DestinationRootFolder "c:\ClusterStorage\$hvhost\VMs" -Cluster $cluster
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment