Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- RT 18APR2018
- #>
- [string]$clusterName
- [string]$vmHosts
- [string]$vmHost
- [string]$clusterHosts
- [int]$nodeCount = 0
- [string]$allVMs
- [string]$vm
- [int]$totalAssignedVMMemory = 0
- [int]$bytesToGB = 0
- [int]$preferredHostMemory = 0
- [string]$hostVMs
- [string]$hostVM
- [int]$totalVMMemory = 0
- [int]$counter = 1
- $bytestoGB = 1073741824
- Clear-Host
- $clusterName = Read-Host "Please enter a cluster to balance"
- $vmHosts = Get-ClusterNode -Cluster $clusterName | Get-VMHost
- $clusterHosts = Get-ClusterNode -Cluster $clusterName
- $nodeCount = $clusterHosts.Count
- $allVMs = Get-ClusterResource -Cluster $clusterName | Where-Object {$_.ResourceType -eq 'Virtual Machine'} | Get-VM
- ForEach($vm in $allVMs)
- {
- $totalAssignedVMMemory = $totalAssignedVMMemory + ($vm.MemoryAssigned/$bytesToGB)
- }
- $preferredHostMemory = $totalAssignedVMMemory/$nodeCount
- ForEach($vmHost in $vmHosts)
- {
- $totalVMMemory = 0
- $hostVMs = Get-VM -ComputerName $vmHost.Name
- ForEach($hostVM in $hostVMs)
- {
- $totalVMMemory = $totalVMMemory + ($vm.MemoryAssigned/$bytesToGB)
- If($totalVMMemory -gt ($preferredHostMemory+10))
- {
- $preferredHostMemory+20
- Move-ClusterVirtualMachineRole -Name $hostVM.Name -Node $vmHosts[$counter].Name
- }
- }
- $counter++
- If($counter -eq $nodeCount)
- {
- $counter = 0
- }
- Write-Host `n
- }
Add Comment
Please, Sign In to add comment