Difference between revisions of "Powercli examples"
Jump to navigation
Jump to search
(Created page with "### auth to api ``` $vCenters = @("vmc01", "vmc02") Connect-VIServer -Server $vCenters ``` ### do stuff ``` # Connect to vCenter server # Connect-VIServer -Server <vCenterSer...") |
|||
Line 23: | Line 23: | ||
# Disconnect from vCenter server | # Disconnect from vCenter server | ||
Disconnect-VIServer -Confirm:$false | 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 | ||
+ | |||
``` | ``` |
Revision as of 23:23, 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