VMware Cloud Community
brianpham
Contributor
Contributor
Jump to solution

Script to turn off VM

Hello,

I am new to VMware. I was wondering if anyone can help me get on the right track. I am trying to find a way to write a script that will check to see if the VMs that have not been used within 90 days and turn power it off.

Any help would be great..

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

In that case you could consider using the cpu.usage.average counter on the VM, and if the average value doesn't exceed a specific threshold, you consider it as not used.

You use the Get-Stat cmdlet to retrieve the metric.

Note that if you back further than 30 days, you will only get 1 metric per day.

This is because of the aggregation that is done, see my PowerCLI & vSphere statistics – Part 1 – The basics post for some more info on that.


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

How do you define "not used" ?

Not powered on, no activity on the VM, no actual logons into the guest OS ... ?


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

brianpham
Contributor
Contributor
Jump to solution

Not used as in no activity on the VM

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case you could consider using the cpu.usage.average counter on the VM, and if the average value doesn't exceed a specific threshold, you consider it as not used.

You use the Get-Stat cmdlet to retrieve the metric.

Note that if you back further than 30 days, you will only get 1 metric per day.

This is because of the aggregation that is done, see my PowerCLI & vSphere statistics – Part 1 – The basics post for some more info on that.


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

0 Kudos