Zade
Enthusiast
Enthusiast

Consolidation power cli script for vms

Jump to solution

We are getting a number of consolidations needed every morning when coming in on our test environments, does anyone know the best way to setup a script to run to consolidate any vms that needed it?

I've tried using the below command:

connect-viserver VCENTERSERVER

Get-VM |

Where-Object {$_.Extensiondata.Runtime.ConsolidationNeeded} |

ForEach-Object {

  $_.ExtensionData.ConsolidateVMDisks()

}

disconnect-viserver VCENTERSERVER -confirm:$FALSE

with a batch file pointing at it -

C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\vim.psc1" "& 'C:\Consolidation_Script\Consolidation_Script.ps1

I've scheduled this, but still seeing vms needing consolidation, can anyone help?

0 Kudos
1 Solution

Accepted Solutions
Prakas
Enthusiast
Enthusiast

May be the script is failing because of PowerCLI snapin not loaded. Try adding the below line to your script (add it as first line) and check if that works.

Add-PSsnapin VMware.VimAutomation.Core

View solution in original post

0 Kudos
2 Replies
Prakas
Enthusiast
Enthusiast

May be the script is failing because of PowerCLI snapin not loaded. Try adding the below line to your script (add it as first line) and check if that works.

Add-PSsnapin VMware.VimAutomation.Core

View solution in original post

0 Kudos
Zade
Enthusiast
Enthusiast

This appears to have worked, I've ran direct from the powershell script and the consolidation jobs have kicked off in vsphere, the only thing I'm concerned about is if the schedule will run.

I'll let you know how we get on after tomorrow.

0 Kudos