Hi Guys a Few Weeks Back i received a Requirement from My Team to get the VM Creation Metrics Till date for Our Hyper-V Environment.Hence i went and created a PowerShell Script to attain the same.
I used the Creation Time Property of VM’s to attain this functionality, i integrated the same with System Center Orchestrator and was able to attain this beautiful view ๐
Here’s the Script Which i used to attain the same.
As the Script Uses SCVMM (System Center Virtual Machine Manager PSSnapin) we need to
Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
<# .SYNOPSIS Hi Guys a Few Weeks Back i received a Requirement from My Team to get the VM Creation Metrics Till date for Our Hyper-V Environment. Hence i went created a PowerShell Script to attain the same. I used the Creation Time Property of VM's to attain this functionality, i integrated the same with System Center Orchestrator and was able to attain this beautiful view :) Here's the Script Which i used to attain the same. As the Script Uses SCVMM (System Center Virtual Machine Manager PSSnapin) we need to Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager .EXAMPLE Log into an SCVMM Server Run Get-VMMServer <Server Name> --> Establish connection to the SCVMM server Get-VM | select name,@{l="VM Creation Month";e={Get-VMCreationMonth $_.name}}` ,@{l="VM Creation Year";e={(Get-VM $_.name | select -ExpandProperty creationtime).Year}}` | Export-Csv "c:Hyper-V_Host_VM_Status.csv" #> function Get-VMCreationMonth{ param ([string]$name = "") $month=(Get-VM $_.name | select -ExpandProperty creationtime).month if($month -eq "1") { $returnedmonth = "January" } elseif($month -eq "2") { $returnedmonth = "February" } elseif($month -eq "3") { $returnedmonth = "March" } elseif($month -eq "4") { $returnedmonth = "April" } elseif($month -eq "5") { $returnedmonth = "May" } elseif($month -eq "6") { $returnedmonth = "June" } elseif($month -eq "7") { $returnedmonth = "July" } elseif($month -eq "8") { $returnedmonth = "August" } elseif($month -eq "9") { $returnedmonth = "September" } elseif($month -eq "10") { $returnedmonth = "October" } elseif($month -eq "11") { $returnedmonth = "November" } elseif($month -eq "12") { $returnedmonth = "December" } return $returnedmonth } Get-VMMServer scvmm01 Get-VM | select name,@{l="VM Creation Month";e={Get-VMCreationMonth $_.name}}` ,@{l="VM Creation Year";e={(Get-VM $_.name | select -ExpandProperty creationtime).Year}}` | Export-Csv "c:Hyper-V_Host_VM_Status.csv" # SIG # Begin signature block # MIID8QYJKoZIhvcNAQcCoIID4jCCA94CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUKWTvxsIWmJzUp8wNqKeAWjyP # UuGgggIQMIICDDCCAXmgAwIBAgIQhlfUKTyJ+75Jv/MCo3iQ8zAJBgUrDgMCHQUA # MBcxFTATBgNVBAMTDFZpbml0aCBNZW5vbjAeFw0xMjEwMjMxMjQ0MDFaFw0zOTEy # MzEyMzU5NTlaMBcxFTATBgNVBAMTDFZpbml0aCBNZW5vbjCBnzANBgkqhkiG9w0B # AQEFAAOBjQAwgYkCgYEA1omAIG/bEKCbtgavJtjjh30PIFGzBi+HU2b16f+NqXiA # vW7OzeiG60M36Ni7hfX8ANak6WfwV0pTiOZXxA65Gml/xU/hdDsM/2BcBRn7X836 # l53KcV3h7c0epM4kifOe5NESk63rkIPxVMjiG+4iGLa6VFbawJ+Tpg0DjlcpnLcC # AwEAAaNhMF8wEwYDVR0lBAwwCgYIKwYBBQUHAwMwSAYDVR0BBEEwP4AQS11gR8gM # 74mXY/Q289zhx6EZMBcxFTATBgNVBAMTDFZpbml0aCBNZW5vboIQhlfUKTyJ+75J # v/MCo3iQ8zAJBgUrDgMCHQUAA4GBAFTg5sfSVA/ngdwToYUzgzfsBiMpTVefmPZ8 # RQuaai1MGdKGYQhllog3JiP49wNoFAogz05O6F2Y+CcaD4uWlRoDYpgmQIcvfO9L # UTHJfOYnZOlUP9XYV3zYTX6euaNj4POnFFHvAucEMhs1b7oQDbyY7x5+MSkmskSY # 0IfbyEuVMYIBSzCCAUcCAQEwKzAXMRUwEwYDVQQDEwxWaW5pdGggTWVub24CEIZX # 1Ck8ifu+Sb/zAqN4kPMwCQYFKw4DAhoFAKB4MBgGCisGAQQBgjcCAQwxCjAIoAKA # AKECgAAwGQYJKoZIhvcNAQkDMQwGCisGAQQBgjcCAQQwHAYKKwYBBAGCNwIBCzEO # MAwGCisGAQQBgjcCARUwIwYJKoZIhvcNAQkEMRYEFEbjf8nfc367E/4h/BSDlq2U # cBy1MA0GCSqGSIb3DQEBAQUABIGA1C7cg/m8QpeFBz9zn1WkyUaIiYzpq9RIPJ7l # gpc7l/i7PEhvqSLCjivQOpDx/uTJivApjbXWTuRP6QtI9jAolizg9gdAUl9rIWgm # YlHHSQbrk6rEZmfDFl4rmu4oGVeTLi8NuOCf6bRnOmrBunQo09RQHJeSomnabrHF # vCThjCo= # SIG # End signature block |
And Here’s the screenshot of The Neat Function Output in a SharePoint List
You can resolve month names in less lines ๐
(Get-Culture).DateTimeFormat.MonthNames[$month-1]
Wow Cool Shay ๐ Thanks, i was not aware of that ๐