From c708d8929d08de169aeda42eef9bfa3dd999d403 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sat, 30 Dec 2023 10:46:04 -0600 Subject: [PATCH] update --- esxi-scripts/get-snapshots.ps1 | 6 ++-- esxi-scripts/host-maintenance_mode.ps1 | 5 ++-- esxi-scripts/iscsi-all-shutdown-verify.ps1 | 30 ++++++++++++++----- esxi-scripts/iscsi-all-vm-shutdown.ps1 | 5 ++-- esxi-scripts/iscsi-server-shutdown.ps1 | 5 ++-- esxi-scripts/iscsi-sys-server-shutdown.ps1 | 9 ------ esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 | 3 -- esxi-scripts/iscsi-sys-vm-shutdown.ps1 | 5 ++-- esxi-scripts/iscsi-vm-shutdown-verify.ps1 | 30 ++++++++++++++----- esxi-scripts/iscsi-vm-shutdown.ps1 | 5 ++-- esxi-scripts/sys-suspend.ps1 | 5 ++-- esxi-scripts/vm-shutdown-verify.ps1 | 30 ++++++++++++++----- esxi-scripts/vm-shutdown.ps1 | 5 ++-- 13 files changed, 90 insertions(+), 53 deletions(-) delete mode 100755 esxi-scripts/iscsi-sys-server-shutdown.ps1 diff --git a/esxi-scripts/get-snapshots.ps1 b/esxi-scripts/get-snapshots.ps1 index 0b2cef75..b917886f 100755 --- a/esxi-scripts/get-snapshots.ps1 +++ b/esxi-scripts/get-snapshots.ps1 @@ -1,11 +1,11 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null -# Connect-VIServer -Server 10.2.1.11 -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null get-vm | get-snapshot | where {($_.vm -notlike '*_replica')} | select vm, name, description, created, sizegb # get-vm | get-snapshot | where {($_.vm -notlike '*_replica')} | select vm, name, description, created, sizegb | ConvertTo-Json -Depth 1 -WarningAction:SilentlyContinue -exit 0 \ No newline at end of file +Disconnect-VIServer $ESXI -Confirm:$false diff --git a/esxi-scripts/host-maintenance_mode.ps1 b/esxi-scripts/host-maintenance_mode.ps1 index d962b648..70695290 100755 --- a/esxi-scripts/host-maintenance_mode.ps1 +++ b/esxi-scripts/host-maintenance_mode.ps1 @@ -1,9 +1,10 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $VCENTERHOST -Protocol https -User $VCENTERUSER -Password $VCENTERPASS | Out-Null +$ESXI = Connect-VIServer -Server $VCENTERHOST -Protocol https -User $VCENTERUSER -Password $VCENTERPASS | Out-Null Get-VMHost -Name $args[0] | set-vmhost -State Maintenance -exit 0 +Disconnect-VIServer $ESXI -Confirm:$false diff --git a/esxi-scripts/iscsi-all-shutdown-verify.ps1 b/esxi-scripts/iscsi-all-shutdown-verify.ps1 index 0043530a..f7bc82c8 100755 --- a/esxi-scripts/iscsi-all-shutdown-verify.ps1 +++ b/esxi-scripts/iscsi-all-shutdown-verify.ps1 @@ -1,16 +1,30 @@ #!/usr/bin/env pwsh -# Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword -$VMLIST = Get-Datastore | Where {$_.Name -like '*iSCSI-*'} | Get-VM +Do { + $VMLIST = Get-Datastore | Where {$_.Name -like '*iSCSI-*'} | Get-VM + write-host $VMLIST + if ($VMLIST -ne $null) { + write-host "cycling through iscsi vms found" + $poff = 'no' + Foreach ($VM in $VMLIST) { + $VMI = Get-VM $VM + if ($VMI -eq $null -Or $VMI.PowerState -match 'PoweredOn') { + $poff = 'no' + break + } else { + $poff = 'yes' + } + } + } else { + write-host "no iscsi vms found" + $poff = 'yes' + } +} Until ($poff -match 'yes') -Foreach ($VM in $VMLIST) { - while((Get-VM $VM).PowerState -ne 'PoweredOff') { - Start-Sleep -Seconds 1 - } -} Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file diff --git a/esxi-scripts/iscsi-all-vm-shutdown.ps1 b/esxi-scripts/iscsi-all-vm-shutdown.ps1 index 101d0675..4eb56c60 100755 --- a/esxi-scripts/iscsi-all-vm-shutdown.ps1 +++ b/esxi-scripts/iscsi-all-vm-shutdown.ps1 @@ -1,9 +1,10 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null Get-Datastore | Where {$_.Name -like '*iSCSI-*'} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*'} | Shutdown-VMGuest -Confirm:$false -exit 0 +Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file diff --git a/esxi-scripts/iscsi-server-shutdown.ps1 b/esxi-scripts/iscsi-server-shutdown.ps1 index 93d748bb..4117f951 100755 --- a/esxi-scripts/iscsi-server-shutdown.ps1 +++ b/esxi-scripts/iscsi-server-shutdown.ps1 @@ -1,9 +1,10 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null Get-VM | Where {$_.Name -like '*iSCSI-*'} | Shutdown-VMGuest -Confirm:$false -exit 0 +Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file diff --git a/esxi-scripts/iscsi-sys-server-shutdown.ps1 b/esxi-scripts/iscsi-sys-server-shutdown.ps1 deleted file mode 100755 index b839e55b..00000000 --- a/esxi-scripts/iscsi-sys-server-shutdown.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env pwsh - -. /opt/idssys/powerwall/settings.ps1 - -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null - -Get-VM | Where {$_.Name -like '*iSCSI-Systems*'} | Shutdown-VMGuest -Confirm:$false - -exit 0 diff --git a/esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 b/esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 index 3a7ea11f..ec2300b3 100755 --- a/esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 +++ b/esxi-scripts/iscsi-sys-vm-shutdown-verify.ps1 @@ -27,7 +27,4 @@ Do { } Until ($poff -match 'yes') - - - Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file diff --git a/esxi-scripts/iscsi-sys-vm-shutdown.ps1 b/esxi-scripts/iscsi-sys-vm-shutdown.ps1 index aa81c4f7..d40f02a1 100755 --- a/esxi-scripts/iscsi-sys-vm-shutdown.ps1 +++ b/esxi-scripts/iscsi-sys-vm-shutdown.ps1 @@ -1,9 +1,10 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null Get-Datastore | Where {$_.Name -like '*iSCSI-SYS*'} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*'} | Shutdown-VMGuest -Confirm:$false -exit 0 +Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file diff --git a/esxi-scripts/iscsi-vm-shutdown-verify.ps1 b/esxi-scripts/iscsi-vm-shutdown-verify.ps1 index c85ce734..c64c540d 100755 --- a/esxi-scripts/iscsi-vm-shutdown-verify.ps1 +++ b/esxi-scripts/iscsi-vm-shutdown-verify.ps1 @@ -1,16 +1,30 @@ #!/usr/bin/env pwsh -# Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword -$VMLIST = Get-Datastore | Where {$_.Name -like '*iSCSI-PRI*'} | Get-VM +Do { + $VMLIST = Get-Datastore | Where {$_.Name -like '*iSCSI-PRI*'} | Get-VM + write-host $VMLIST + if ($VMLIST -ne $null) { + write-host "cycling through iscsi vms found" + $poff = 'no' + Foreach ($VM in $VMLIST) { + $VMI = Get-VM $VM + if ($VMI -eq $null -Or $VMI.PowerState -match 'PoweredOn') { + $poff = 'no' + break + } else { + $poff = 'yes' + } + } + } else { + write-host "no iscsi vms found" + $poff = 'yes' + } +} Until ($poff -match 'yes') -Foreach ($VM in $VMLIST) { - while((Get-VM $VM).PowerState -ne 'PoweredOff') { - Start-Sleep -Seconds 1 - } -} Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file diff --git a/esxi-scripts/iscsi-vm-shutdown.ps1 b/esxi-scripts/iscsi-vm-shutdown.ps1 index 2ab7b94b..9f5bcbf8 100755 --- a/esxi-scripts/iscsi-vm-shutdown.ps1 +++ b/esxi-scripts/iscsi-vm-shutdown.ps1 @@ -1,9 +1,10 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null Get-Datastore | Where {$_.Name -like '*iSCSI-PRI*'} | Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*'} | Shutdown-VMGuest -Confirm:$false -exit 0 +Disconnect-VIServer $ESXI -Confirm:$false diff --git a/esxi-scripts/sys-suspend.ps1 b/esxi-scripts/sys-suspend.ps1 index b7a02a61..069e8194 100755 --- a/esxi-scripts/sys-suspend.ps1 +++ b/esxi-scripts/sys-suspend.ps1 @@ -1,9 +1,10 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null Get-VM | Where {$_.PowerState -like '*On*' -and ($_.Name -like '*MySQL-Node*' -or $_.Name -like '*LAN-DNS*')} | Suspend-VM -Confirm:$false -exit 0 +Disconnect-VIServer $ESXI -Confirm:$false diff --git a/esxi-scripts/vm-shutdown-verify.ps1 b/esxi-scripts/vm-shutdown-verify.ps1 index ede4064f..60a73198 100755 --- a/esxi-scripts/vm-shutdown-verify.ps1 +++ b/esxi-scripts/vm-shutdown-verify.ps1 @@ -1,16 +1,30 @@ #!/usr/bin/env pwsh -# Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword -$VMLIST = Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'} +Do { + $VMLIST = Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'} + write-host $VMLIST + if ($VMLIST -ne $null) { + write-host "cycling through iscsi vms found" + $poff = 'no' + Foreach ($VM in $VMLIST) { + $VMI = Get-VM $VM + if ($VMI -eq $null -Or $VMI.PowerState -match 'PoweredOn') { + $poff = 'no' + break + } else { + $poff = 'yes' + } + } + } else { + write-host "no iscsi vms found" + $poff = 'yes' + } +} Until ($poff -match 'yes') -Foreach ($VM in $VMLIST) { - while((Get-VM $VM).PowerState -ne 'PoweredOff') { - Start-Sleep -Seconds 1 - } -} Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file diff --git a/esxi-scripts/vm-shutdown.ps1 b/esxi-scripts/vm-shutdown.ps1 index d4b8b4fd..714e19c5 100755 --- a/esxi-scripts/vm-shutdown.ps1 +++ b/esxi-scripts/vm-shutdown.ps1 @@ -1,9 +1,10 @@ #!/usr/bin/env pwsh +Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null . /opt/idssys/powerwall/settings.ps1 -Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null +$ESXI = Connect-VIServer -Server $args[0] -Protocol https -User $ESXiUsername -Password $ESXiPassword | Out-Null Get-VM | Where {$_.PowerState -like '*On*' -and $_.Name -notlike '*CLS*' -and $_.Name -notlike '*iSCSI*'} | Shutdown-VMGuest -Confirm:$false -exit 0 +Disconnect-VIServer $ESXI -Confirm:$false \ No newline at end of file