-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovisioningresource.ps1
More file actions
79 lines (66 loc) · 2.69 KB
/
provisioningresource.ps1
File metadata and controls
79 lines (66 loc) · 2.69 KB
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
<#
.SYNOPSIS
PowerCLI script to calculate total provisioned resources (VM count, vCPUs, RAM)
across all ESXi hosts in a vCenter or cluster.
.DESCRIPTION
- Connects to a vCenter server using VMware PowerCLI
- Iterates through each ESXi host
- Collects total number of powered-on VMs, provisioned vCPU cores, and provisioned RAM
- Displays results per host and aggregated cluster totals
.REQUIREMENTS
- VMware PowerCLI module installed
- Network connectivity to vCenter
- User with read privileges on vCenter and ESXi hosts
.NOTES
Author: Your Name
GitHub: https://github.com/yourrepo/cloud-automation
License: MIT
#>
# Disable SSL certificate warnings (optional, not recommended for production)
Set-PowerCLIConfiguration -InvalidCertificateAction:Ignore -Confirm:$false | Out-Null
# =========================
# User Variables
# =========================
# Replace these placeholders with your vCenter credentials and address
$vcenter_user = "your-username@domain.local"
$vcenter_pass = "your-password" # ⚠️ Consider using Get-Credential or a secure vault
$vcenter_add = "your-vcenter.domain.local"
# Connect to vCenter
Connect-VIServer -Server $vcenter_add -User $vcenter_user -Password $vcenter_pass
# Get all ESXi hosts in vCenter
# (To scope to a specific cluster, use: Get-Cluster -Name "ClusterName" | Get-VMHost)
$vmhosts = Get-VMHost
# Initialize cluster totals
$clusterTotals = [PSCustomObject]@{
TotalVMs = 0
TotalCPU = 0
TotalRAMGB = 0
}
# =========================
# Loop through each ESXi host
# =========================
foreach ($esxi in $vmhosts) {
# Get powered-on VMs on the host
$poweredOnVMs = Get-VM -Location $esxi | Where-Object {$_.PowerState -eq 'PoweredOn'}
# Calculate totals per host
$vmCount = $poweredOnVMs.Count
$cpuTotal = ($poweredOnVMs | Measure-Object -Property NumCPU -Sum).Sum
$ramTotal = ($poweredOnVMs | Measure-Object -Property MemoryGB -Sum).Sum
# Print per-host info
Write-Host "Host: $($esxi.Name)" -ForegroundColor Cyan
Write-Host " Running VMs : $vmCount"
Write-Host " Provisioned vCPUs : $cpuTotal"
Write-Host " Provisioned RAMGB : $ramTotal"
Write-Host ""
# Add to cluster totals
$clusterTotals.TotalVMs += $vmCount
$clusterTotals.TotalCPU += $cpuTotal
$clusterTotals.TotalRAMGB += $ramTotal
}
# =========================
# Print overall cluster totals
# =========================
Write-Host "===== Cluster Totals =====" -ForegroundColor Green
Write-Host "Total Running VMs : $($clusterTotals.TotalVMs)"
Write-Host "Total Provisioned vCPUs : $($clusterTotals.TotalCPU)"
Write-Host "Total Provisioned RAMGB : $($clusterTotals.TotalRAMGB)"