PowerCLI Script – Report Powered off VM’s older than 30 days

Most of the time, we will be excited to create or run PowerCLI Script to accomplish the tasks within short period of time by eliminating lot of manual process. In most of the enterprise environment, I feel 2 tasks (VM Build & VM Decommission) which is very difficult to track due to its high volume. Among these 2 tasks, tracking VM for decommission  is the tough tasks. Respective application or developer team have given go ahead for decommission the virtual machines. Support team would have powered off that virtual machines but forgot to delete the VM because there are lot of different process may be evolved with the VM deletion and decommission.  Due to that, lot of virtual machines would have left out and lying in clusters and datastores in powered off state by occupying lot of costlier storage space. So we need to keep track of that powered off virtual machines. I believe Virtual machines in powered off state for atleast 30 days would be good candidate for decommission. This PowerCLI Script will help you to get the report with the list of Powered off virtual machines which is older than 30 days in the vCenter server. This report will help you to find the good candidate for decommission to reclaim the occupied storage to save the cost to your organization.

PowerCLI Script – Report Powered off VM’s older than 30 days

How to Execute the Script?

Copy and Paste the above Script and save it in the Notepad. Name the script as “VMPoweredoff30DaysAgo.ps1″

  1. Execute the Script in PowerCLI “.\VMPoweredoff30DaysAgo.ps1
  2. Input  vCenter Server Name to execute the script to get the report of powered off VM’s older than 30 days
  3. Enter the Username with administrative credentials on vCenter Server
  4. Enter the password for the above entered Username
  5. Hit Enter to execute the script and pull the report.

PowerCLI Script

Script Output

Virtual machines powered off older than 30 days report will be exported and saved in the Microsoft Excel output file with the filename “VMPoweredOff_Today_Date-time.CSV” under the same directory where the PowerCLI Script “VMPoweredoff30DaysAgo.ps1.ps1”  is located.

PowerCLI Script

I hope script will be useful for you to save lot of time and avid manual works. Thanks for Reading !!! Be social and share it in social media, if you feel worth sharing it.