Posted in
Virtual Machine Manager,
Windows Powershell |
No Comment | 3,309 views | 08/05/2009 18:32
Today, I’m going to share my new script called “SCVMM Suggestion Script v1.0”. The hardest thing is finding best VMHost and Hard Disk Drive. You have to check available RAM and check all VM Disk Paths to find best server. But you don’t have to do that anymore. You can use “SCVMM Suggestion Script v1.0”.
What does this script do?
Find best server which has more available ram.
Find best hdd drive which has less vhd.
This script built for my environment. But It should work for you too. Just you need to change “disk checking part” for your own environment.
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
| # SCVMM Suggestion Script v1.0
# Created by Yusuf Ozturk
# http://www.yusufozturk.info
$SuggestVMHostProp = Get-VMHost | Select-Object -Property Name,AvailableMemory
$SuggestBestServer = $SuggestVMHostProp | sort-object AvailableMemory | Select-Object -Last 1
$SuggestVMHost = $SuggestBestServer.Name
$SuggestVMProp = Get-VMHost $SuggestVMHost | Get-VM
$SuggestBestDisk = $SuggestVMProp | Get-VirtualHardDisk | sort-object Location
$DriveC = ($SuggestBestDisk | Where-Object {$_.Location -match "^C:*"}).count
$DriveD = ($SuggestBestDisk | Where-Object {$_.Location -match "^D:*"}).count
$DriveE = ($SuggestBestDisk | Where-Object {$_.Location -match "^E:*"}).count
$DriveF = ($SuggestBestDisk | Where-Object {$_.Location -match "^F:*"}).count
IF ($DriveD -gt $DriveE)
{
$SuggestBestDrive = "$DriveE"
$SuggestDriveName = "E"
}
ELSE
{
$SuggestBestDrive = "$DriveD"
$SuggestDriveName = "D"
}
IF ($DriveF -ne $NULL)
{
IF ($SuggestBestDrive -gt $DriveF)
{
$SuggestBestDrive = "$DriveF"
$SuggestDriveName = "F"
}
}
Write-Host Best Host is $SuggestVMHost
Write-Host Best Drive is $SuggestDriveName |
# SCVMM Suggestion Script v1.0
# Created by Yusuf Ozturk
# http://www.yusufozturk.info
$SuggestVMHostProp = Get-VMHost | Select-Object -Property Name,AvailableMemory
$SuggestBestServer = $SuggestVMHostProp | sort-object AvailableMemory | Select-Object -Last 1
$SuggestVMHost = $SuggestBestServer.Name
$SuggestVMProp = Get-VMHost $SuggestVMHost | Get-VM
$SuggestBestDisk = $SuggestVMProp | Get-VirtualHardDisk | sort-object Location
$DriveC = ($SuggestBestDisk | Where-Object {$_.Location -match "^C:*"}).count
$DriveD = ($SuggestBestDisk | Where-Object {$_.Location -match "^D:*"}).count
$DriveE = ($SuggestBestDisk | Where-Object {$_.Location -match "^E:*"}).count
$DriveF = ($SuggestBestDisk | Where-Object {$_.Location -match "^F:*"}).count
IF ($DriveD -gt $DriveE)
{
$SuggestBestDrive = "$DriveE"
$SuggestDriveName = "E"
}
ELSE
{
$SuggestBestDrive = "$DriveD"
$SuggestDriveName = "D"
}
IF ($DriveF -ne $NULL)
{
IF ($SuggestBestDrive -gt $DriveF)
{
$SuggestBestDrive = "$DriveF"
$SuggestDriveName = "F"
}
}
Write-Host Best Host is $SuggestVMHost
Write-Host Best Drive is $SuggestDriveName
I don’t know how to find best drive in easy way so I used if/else statements. If you know better way, please share with me. I hope it works for you.