This commit is contained in:
2024-01-31 10:54:49 -06:00
parent 5dd0aa87c7
commit 21bb76a430
2 changed files with 16 additions and 35 deletions

View File

@@ -1,32 +1,14 @@
#!/usr/bin/env pwsh #!/usr/bin/env pwsh
. /opt/idssys/powerwall/settings.ps1 . /opt/idssys/powerwall/settings.ps1
Connect-VIServer -Server $VCENTERHOST -Protocol https -User $VCENTERUSER -Password $VCENTERPASS
# Connect-VIServer -Server $VCENTERHOST -Protocol https -User $VCENTERUSER -Password $VCENTERPASS | Out-Null # Connect-VIServer -Server $VCENTERHOST -Protocol https -User $VCENTERUSER -Password $VCENTERPASS | Out-Null
write-host connected
#Get-VMHost | Where {$args[0]} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'} | Shutdown-VMGuest -Confirm:$false
$vmhosts=$args[0].Split(",") $vmhosts=$args[0].Split(",")
Foreach ($vmhost in $vmhosts) Foreach ($vmhost in $vmhosts)
{ {
write-host $vmhost write-host $vmhost
Get-VMHost | Where {$_.Name -eq $vmhost} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'} # Get-VMHost | Where {$_.Name -eq $vmhost} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'} | Shutdown-VMGuest -Confirm:$false
} }
# $vmhosts=Get-VMHost
# & $vmhosts=$vmhosts | Where {$args[0]}
# write-host $COMMAND
# $COMMAND="Get-VMHost | Where {"+$args[0]+"} | Get-VM"
# write-host $COMMAND
# & $COMMAND | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'}
# Disconnect-VIServer -Server $VCENTERHOST -Force Confirm:$false # Disconnect-VIServer -Server $VCENTERHOST -Force Confirm:$false
#$_.Name -eq 'ids-vms1.scity.us' -or $_.Name -eq 'ids-vms7.scity.us'

View File

@@ -11,7 +11,7 @@ source /opt/idssys/powerwall/inc/power.inc.sh
source /opt/idssys/powerwall/inc/temp.inc.sh source /opt/idssys/powerwall/inc/temp.inc.sh
# TEST=true TEST=true
shopt -s lastpipe shopt -s lastpipe
@@ -416,21 +416,20 @@ SHUTDOWN_SERVER(){
echo echo
fi fi
for ESXIHOST in "${ESXI_HOSTS[@]}"; do MSG="Shutting down remaining VM's on: ${PW_ESXI_HOST_NAMES[${ESXIHOST}]}"
MSG="Shutting down remaining VM's on: ${PW_ESXI_HOST_NAMES[${ESXIHOST}]}" c=0; MSG_SPC=''; spc1=`expr ${HC_CW} - ${#MSG}`; until [ ${c} = ${spc1} ]; do MSG_SPC="${MSG_SPC} "; ((c++)); done
c=0; MSG_SPC=''; spc1=`expr ${HC_CW} - ${#MSG}`; until [ ${c} = ${spc1} ]; do MSG_SPC="${MSG_SPC} "; ((c++)); done echo -en "${idsCL[White]}${MSG//${PW_ESXI_HOST_NAMES[${ESXIHOST}]}/${idsCL[LightCyan]}${PW_ESXI_HOST_NAMES[${ESXIHOST}]}}${idsCL[White]}${MSG_SPC}: "
echo -en "${idsCL[White]}${MSG//${PW_ESXI_HOST_NAMES[${ESXIHOST}]}/${idsCL[LightCyan]}${PW_ESXI_HOST_NAMES[${ESXIHOST}]}}${idsCL[White]}${MSG_SPC}: " if [ "${TEST}" != "true" ]; then
if [ "${TEST}" != "true" ]; then for ESXIHOST in "${ESXI_HOSTS[@]}"; do
if [ "$(ipmitool -I lanplus -H ${PW_HOST_IDRACS[${PW_ESXI_HOST_NAMES[${ESXIHOST}]}]} -U ${PW_ESXI_USER} -P "${PW_ESXI_PASS}" chassis power status | grep 'Power is on')" != "" ]; then var="${ESXIHOST},${var}"
${PW_FOLDER}/esxi-scripts/vm-shutdown.ps1 ${ESXIHOST} >/dev/null 2>&1 & done
echo -e "${idsCL[Green]}Commands sent${idsCL[Default]}" echo "HERE: ${var::-1}"
else ${PW_FOLDER}/esxi-scripts/vm-shutdown.ps1 ${var::-1} #>/dev/null 2>&1 &
echo -e "${idsCL[Yellow]}Host Offline${idsCL[Default]}" echo -e "${idsCL[Green]}Commands sent${idsCL[Default]}"
fi
else else
echo -e "${idsCL[Yellow]}(TEST MODE)${idsCL[Default]}" echo -e "${idsCL[Yellow]}(TEST MODE)${idsCL[Default]}"
fi fi
done
echo echo
if [ ${MM} -eq 0 ]; then if [ ${MM} -eq 0 ]; then