VMware Cloud Community
jdefilippis
Contributor
Contributor

Automation for powered off vms

Hi All,

Does anyone know if there is a way to automate moving powered off VMs to a virtual machine folder?  I'm performing a manual method of exporting powered off vms to an excel sheet and joining the vms and commands to a listed output.  Then running the list of powercli commands in a batch. 

PowerCLI

move-vm VM1  -Destination "Powered Off VMs"

Thanks!

Jason

4 Replies
LucD
Leadership
Leadership

You could do something like this

Get-VM | where{$_.PowerState -eq 'PoweredOff'} |

ForEach-Object -Process {

    Move-VM -VM $_ -InventoryLocation 'Powered Off VMs'

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

jdefilippis
Contributor
Contributor

Thanks LucD!

Is there a way to list powered off vms we don't want to move like server or citrix templates?

0 Kudos
LucD
Leadership
Leadership

If you have a rule to select those, then that can be added to the Where-clause condition.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

SasoB
Contributor
Contributor

I am using Custom Atributtes for this. I have field DeleteOnDate and if it empty I move VM to selected folder and add a new date to custom attribute. If there is a date in the field I don't move it and also if VM is detected as powered On I empty the field.

0 Kudos