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 | 1,726 views | 19/06/2009 23:23

Hyper-v allocates ram and you can’t create more virtual machines if you don’t have enough ram on your hyperv servers. If you have an automatic deploy script, you can miss available rams on Hyperv servers. So I created a script, checking all hyperv servers and if ram is less than a limit, it sends you an order mail.

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
Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager
Get-Vmmserver localhost
 
$VMHostProp = Get-VMHost hyperv*
$BestServer = $VMHostProp | sort-object AvailableMemory | Select-Object -Last 1
$VMCount = $BestServer.VMs.Count
 
IF ($BestServer.AvailableMemory -lt "1500")
{
$satir01 = 'Hello,'
$satir02 = ' '
$satir03 = 'There are not enough rams on Hyperv servers.'
$satir04 = 'Maximum available ram is on ' + $BestServer.Name + ' server.'
$satir05 = ' '
$satir06 = 'For more information, ' + $BestServer.Name + ' specifications:'
$satir07 = 'Available ram: ' + $BestServer.AvailableMemory
$satir08 = 'Total vms on server: ' + $VMCount
$satir09 = 'Total hdds on server: ' + $BestServer.DiskVolumes.Count
$satir10 = ' '
$satir11 = 'Regards,'
$satir12 = 'Powershell'
clear-content -path "C:\VMMLibrary\stokdurumu.txt"
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir01
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir02
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir03
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir04
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir05
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir06
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir07
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir08
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir09
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir10
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir11
add-content -path C:\VMMLibrary\stokdurumu.txt -value $satir12
C:\VMMLibrary\mail.exe -s mx.gmail.com -t team@yusufozturk.info -f status@yusufozturk.info -h -a "Hyperv Status" -m C:\VMMLibrary\stokdurumu.txt -c
}

Mail.exe is a mail sender exe for command prompt. You can easily find a cmd mailer for this scenario.