Difference between revisions of "Powercli examples"
Jump to navigation
Jump to search
| Line 49: | Line 49: | ||
# Disconnect from vCenter server | # Disconnect from vCenter server | ||
Disconnect-VIServer -Confirm:$false | Disconnect-VIServer -Confirm:$false | ||
| + | |||
| + | ``` | ||
| + | |||
| + | ### Max Memory | ||
| + | ``` | ||
| + | # Specify the start and end dates for the 7-day period | ||
| + | $endDate = Get-Date | ||
| + | $startDate = $endDate.AddDays(-7) | ||
| + | |||
| + | # Get memory usage statistics for the specified cluster in the 7-day period | ||
| + | $memoryStats = Get-Stat -Entity (Get-Cluster -Name $clusterName) -Stat "mem.usage.average" -Start $startDate -Finish $endDate -MaxSamples 1 -IntervalMins 5 | ||
| + | |||
| + | # Find the maximum memory usage value | ||
| + | $maxMemoryUsage = $memoryStats | Measure-Object -Property Value -Maximum | Select-Object -ExpandProperty Maximum | ||
| + | |||
| + | # Display the result | ||
| + | Write-Host "Maximum Memory Usage in the last 7 days for Cluster '$clusterName': $maxMemoryUsage%" | ||
``` | ``` | ||
Revision as of 23:26, 6 February 2024
auth to api
$vCenters = @("vmc01", "vmc02")
Connect-VIServer -Server $vCenters
do stuff
# Connect to vCenter server
# Connect-VIServer -Server <vCenterServer> -User <Username> -Password <Password>
# Specify the cluster name
$clusterName = "YourClusterName"
# Get all virtual machines on the specified cluster
$vmList = Get-VM -Location (Get-Cluster -Name $clusterName)
# Display information about each virtual machine
foreach ($vm in $vmList) {
Write-Host "VM Name: $($vm.Name) | Cluster: $($vm.Cluster) | PowerState: $($vm.PowerState)"
}
# Disconnect from vCenter server
Disconnect-VIServer -Confirm:$false
Max CPU
# Connect to vCenter server Connect-VIServer -Server <vCenterServer> -User <Username> -Password <Password> # Specify the cluster name $clusterName = "YourClusterName" # Specify the start and end dates for the 7-day period $endDate = Get-Date $startDate = $endDate.AddDays(-7) # Get CPU usage statistics for the specified cluster in the 7-day period $cpuStats = Get-Stat -Entity (Get-Cluster -Name $clusterName) -Stat "cpu.usage.average" -Start $startDate -Finish $endDate -MaxSamples 1 -IntervalMins 5 # Find the maximum CPU usage value $maxCpuUsage = $cpuStats | Measure-Object -Property Value -Maximum | Select-Object -ExpandProperty Maximum # Display the result Write-Host "Maximum CPU Usage in the last 7 days for Cluster '$clusterName': $maxCpuUsage%" # Disconnect from vCenter server Disconnect-VIServer -Confirm:$false
Max Memory
# Specify the start and end dates for the 7-day period $endDate = Get-Date $startDate = $endDate.AddDays(-7) # Get memory usage statistics for the specified cluster in the 7-day period $memoryStats = Get-Stat -Entity (Get-Cluster -Name $clusterName) -Stat "mem.usage.average" -Start $startDate -Finish $endDate -MaxSamples 1 -IntervalMins 5 # Find the maximum memory usage value $maxMemoryUsage = $memoryStats | Measure-Object -Property Value -Maximum | Select-Object -ExpandProperty Maximum # Display the result Write-Host "Maximum Memory Usage in the last 7 days for Cluster '$clusterName': $maxMemoryUsage%"