不确定 CPU 使用情况,但您可以在内存上使用 PowercLI get-stat 并围绕它建立一些逻辑。快速示例:
connect-viserver my_vc
$active = (get-stat -entity (get-cluster cluster_name | get-resourcepool Low) -stat mem.active.average -maxsamples 1 -realtime).Value
$granted = (get-stat -entity (get-cluster cluster_name | get-resourcepool Low) -stat mem.granted.average -maxsamples 1 -realtime).Value
$active
$granted
$pctused = ($active / $granted)*100
$pctused
# 4445929
# 31797248
# 13.9821188299063
我想你可以在构建之前运行它并在条件语句中使用 $pctused 例如 if ($pctused -lt 98) { # build } else { # stop gracefully }