search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Virtual Machine Manager, Windows Powershell | No Comment | 22,195 views | 28/04/2009 01:52

I haven’t post any scripts for a long time because I’m writing IIS7 scripts nowadays. Using IIS7 Powershell Snaping is real fun. But let’s back to the SCVMM and do something different. How about VM Uptimes? As you know, there is no powershell command to see vm uptimes with using SCVMM Snapin (or I don’t know that command) So, now I’ll use Hyper-V snapin codes to take that uptimes and I’ll write it to a xml file. Let’s see the codes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
 
$VMProp = Get-VM | Select-Object -Property Name,VMHost
foreach ($i in $VMProp)
{
$VMName = $i.Name
write-host $VMName
$VMHost = $i.VMHost
write-host $VMHost
$VMState
Function Get-VM 
Filter Get-VMSettingData
Filter Get-VMSummary
$Uptime = Get-VMSummary -VM $VMName -Server $VMHost
$VMUptime = $Uptime.UptimeFormatted
$contentStatus = '        <Uptime>' + $VMUptime + '</Uptime>'
clear-content -path "C:\Program Files\Microsoft System Center Virtual Machine Manager 2008\wwwroot\Uptime\$VMName.xml"
add-content -path "C:\Program Files\Microsoft System Center Virtual Machine Manager 2008\wwwroot\Uptime\$VMName.xml" -value '<?xml version="1.0"?>'
add-content -path "C:\Program Files\Microsoft System Center Virtual Machine Manager 2008\wwwroot\Uptime\$VMName.xml" -value '<serverSettings>'
add-content -path "C:\Program Files\Microsoft System Center Virtual Machine Manager 2008\wwwroot\Uptime\$VMName.xml" -value $contentStatus
add-content -path "C:\Program Files\Microsoft System Center Virtual Machine Manager 2008\wwwroot\Uptime\$VMName.xml" -value '</serverSettings>'
}

As you see, using Hyper-v Snapin Get-VMSummary command is really easy. But what should I do? Should I use that command for every single VM? We have more than 300 vms. I don’t have any time to do that. So what i did?
First, I used SCVMM Snapin to catch all VMs. Then I used “foreach” to use Hyper-v Snapin on all VM’s in my enviroment. I made it a batch file and I can refresh VM Uptimes in a period of time with using this script.

You can download SCVMM Uptime Script from here:

You can parse that xml files and list them in a web application.