PoshCode Logo PowerShell Code Repository

Get-VMCreationReport by Carter Shanklin 23 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1679"></script>download | new post

Produces a report of the number of and names of VMs created broken down by month and year.

  1. # Report VMs created per month.
  2. # Before you begin run Alan's "Who Created that VM?" script.
  3. # http://www.virtu-al.net/2010/02/23/who-created-that-vm/
  4. function Get-VMCreationReport {
  5.         Get-VM | Group {
  6.                 if ($_.CustomFields["CreatedOn"] -as [DateTime] -ne $null) {
  7.                         "{0:Y}" -f [DateTime]$_.CustomFields["CreatedOn"]
  8.                 } else {
  9.                         "Unknown"
  10.                 }
  11.         }
  12. }
  13.  
  14. # To create a CSV of this stuff try:
  15. # Get-VMCreationReport | select Count, Name, { $_.Group -as [String] } |
  16. #       export-csv c:\report.csv -NoTypeInformation

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me