-
Notifications
You must be signed in to change notification settings - Fork 50
/
Start-RulesQuery.ps1
66 lines (49 loc) · 1.79 KB
/
Start-RulesQuery.ps1
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
# Data exported to a CSV:
# * Cluster (given a number to not give true cluster name)
# * Cluster Size (used to understand potential complexity of the DRS Rules)
# * Total number of DRS Rules (Just a count, no other info)
# * Total number of VMs included in the rules (Just a count, no other info)
# * Average VMs per DRS rule (just a calculation between the other two numbers)
# Must be connected to vCenter (Connect-VIServer cmdlet)
# This script does a single read-only query (Get-Cluster).
# No data is being pushed back into the environment and as
# the one cmdlet run is a Read-Only
function start-rulesQuery {
# Create an array for the objects below
$clusters = @()
# For each cluster, run the following
$i = 1
foreach ($cls in (get-cluster)) {
# Variable for the DRS Rules
$rules = $cls.ExtensionData.Configuration.Rule
# Variable for the number of DRS Rules
$numRules = $rules.count
# Variable for the total number of VMs included in DRS rules
$numVMs = $rules.vm.count
# Calculate the averate nume of VMs per DRS rule
if ($numVMs -gt 0 -and $numRules -gt 0) {
$AVGVMsPerRule = ($numVMs / $numRules)
}
else {$AVGVMsPerRule = 0}
# Organize the output
$reporthash = [ordered]@{
CLSName = "Cluster$i"
Clustersize = $cls.ExtensionData.host.count
NumRules = $numRules
NumVMs = $numVMs
AVGVMs = $AVGVMsPerRule
}
# Create the object from the above Hashtable
$clsobject = New-object -typename psobject -Property $reporthash
# Add the object to the array first specified
$clusters += $clsobject
$i++
}
# Returns the data
return $clusters
}
# Runs the above function and exports to a CSV, Path needs to be specified
Start-rulesQuery | export-csv -Path "" -NoTypeInformation
Write-Host "Please email results to [email protected]" -ForegroundColor Cyan
# Please email results to [email protected]
# Thank you for your help