build 7bbbddf7 | content blog-content@c8490fa · 338 posts | profiles 20 · corpus 267 | 0 skipped | | format
apiVersion: soultec.ch/v1kind: Postmetadata: name: powercli-automating-vm-shutdown-triggered-by-usv locale: en labels: author: dario-doerflinger capability/virtualization: 1.37 capability/automation: 1.78 vendor/vmware: 0.88 annotations: source: blog-content/posts/en/powercli-automating-vm-shutdown-triggered-by-usv.md route: /en/insights/powercli-automating-vm-shutdown-triggered-by-usv/ schema: /nerd/schema/posts.json markdown: /en/insights/powercli-automating-vm-shutdown-triggered-by-usv.mdspec: title: Automating VM Shutdown triggered by USV date: 2017-07-21 author: dario-doerflinger locale: en summary: >- So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure. capabilities: [virtualization, automation] vendors: [vmware] legacySlug: powercli-automating-vm-shutdown-triggered-by-usv migrated: 2026-08-24 draft: false sections: - body: | So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure. I started to write the following script, but it has not been finalized because some of the customer's engineers are on holidays. I will update this post as soon as the final script is ready. One thing to note: It uses the same VI Credential Store as my previous script to automate VM skeleton creation. Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts). ```powershell ############################################################################################ # Script name: EvacuateVMsFromUSV.ps1 # Description: Evacuate all VMs from one site in a active-active cluster and shut down the Hosts # Version: 1.0 # Date: 20.07.2017 # Author: Dario Doerflinger (virtualfrog.wordpress.com) # History: 20.07.2017 - First tested release ############################################################################################ # Example: # e.g.: .\EvacuateVMsFromUSV.ps1 -SiteToShutdown Allschwil param ( [string]$SiteToShutdown # Identifier of site ) $vCenter_server = "bezhvcs03.bechtlezh.ch" # clear global ERROR variable $Error.Clear() # import vmware related modules, get the credentials and connect to the vCenter server Import-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null Import-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue |Out-Null $creds = Get-VICredentialStoreItem -file "C:\Users\Administrator\Desktop\login.creds" Connect-VIServer -Server $vCenter_server -User $creds.User -Password $creds.Password |Out-Null # define global variables $current_date = $(Get-Date -format "dd.MM.yyyy HH:mm:ss") $log_file = "C:\Users\Administrator\Desktop\\log_$(Get-Date -format "yyyyMMdd").txt" Function SetDRStoAutomatic ($cluster) { try { $cluster | Set-Cluster -DrsEnabled:$true -DrsAutomationLevel FullyAutomated -Confirm:$false |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not set DRS Mode to automatic" } } Function RemoveRemovableMediaFromVMs($esxhost) { try { $esxhost | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not get the vm objects from host." } } Function EvacuateVMsFromHost($esxhost) { try { $esxhost | Set-VMHost -State Maintenance -Evacuate:$true -Confirm:$false |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not put host into maintenance mode" } } Function ShutDownHost($esxhost) { try { $esxhost | Stop-VMhost -Confirm:$false -Whatif } catch { Write-Host -Foregroundcolor:red "Could not shut down host" } } ###### Main Program ###### if ($SiteToShutdown -eq "Allschwil") { $hosts = @("bezhesx40.bechtlezh.ch") } elseif ($SiteToShutdown -eq "Pratteln") { $hosts = @("bezhesx41.bechtlezh.ch") } foreach ($esxhost in $hosts) { $cluster = (get-vmhost $esxhost).Parent SetDRStoAutomatic($cluster) $esxihost = Get-VMhost $esxhost RemoveRemovableMediaFromVMs($esxihost) EvacuateVMsFromHost($esxihost) ShutDownHost($esxihost) } # cleanup and removal of loaded VMware modules Disconnect-VIServer -Server $vCenter_server -Confirm:$false |Out-Null Remove-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue | Out-Null Remove-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null # write all error messages to the log file Add-Content -Path $log_file -Value $Error ```status: corpus: 267 alsoLike: - {ref: services/platform, score: 0.85} - {ref: solutions/vmware/vmware-cloud-foundation, score: 0.73} - {ref: solutions/vmware/vmware-cloud-foundation/vcf-automation, score: 0.73}
{ "apiVersion": "soultec.ch/v1", "kind": "Post", "metadata": { "name": "powercli-automating-vm-shutdown-triggered-by-usv", "locale": "en", "labels": { "author": "dario-doerflinger", "capability/virtualization": "1.37", "capability/automation": "1.78", "vendor/vmware": "0.88" }, "annotations": { "source": "blog-content/posts/en/powercli-automating-vm-shutdown-triggered-by-usv.md", "route": "/en/insights/powercli-automating-vm-shutdown-triggered-by-usv/", "schema": "/nerd/schema/posts.json", "markdown": "/en/insights/powercli-automating-vm-shutdown-triggered-by-usv.md" } }, "spec": { "title": "Automating VM Shutdown triggered by USV", "date": "2017-07-21", "author": "dario-doerflinger", "locale": "en", "summary": "So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure.", "capabilities": [ "virtualization", "automation" ], "vendors": [ "vmware" ], "legacySlug": "powercli-automating-vm-shutdown-triggered-by-usv", "migrated": "2026-08-24", "draft": false }, "sections": [ { "body": "So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure.\n\nI started to write the following script, but it has not been finalized because some of the customer's engineers are on holidays. I will update this post as soon as the final script is ready.\n\nOne thing to note: It uses the same VI Credential Store as my previous script to automate VM skeleton creation.\n\nUpdate: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).\n\n```powershell\n\n############################################################################################\n# Script name: EvacuateVMsFromUSV.ps1\n# Description: Evacuate all VMs from one site in a active-active cluster and shut down the Hosts\n# Version: 1.0\n# Date: 20.07.2017\n# Author: Dario Doerflinger (virtualfrog.wordpress.com)\n# History: 20.07.2017 - First tested release\n############################################################################################\n\n# Example: # e.g.: .\\EvacuateVMsFromUSV.ps1 -SiteToShutdown Allschwil\n\nparam (\n [string]$SiteToShutdown # Identifier of site\n)\n$vCenter_server = \"bezhvcs03.bechtlezh.ch\"\n# clear global ERROR variable\n$Error.Clear()\n\n# import vmware related modules, get the credentials and connect to the vCenter server\nImport-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null\nImport-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue |Out-Null\n$creds = Get-VICredentialStoreItem -file \"C:\\Users\\Administrator\\Desktop\\login.creds\"\nConnect-VIServer -Server $vCenter_server -User $creds.User -Password $creds.Password |Out-Null\n\n# define global variables\n\n$current_date = $(Get-Date -format \"dd.MM.yyyy HH:mm:ss\")\n$log_file = \"C:\\Users\\Administrator\\Desktop\\\\log_$(Get-Date -format \"yyyyMMdd\").txt\"\n\nFunction SetDRStoAutomatic ($cluster)\n{\n try {\n $cluster | Set-Cluster -DrsEnabled:$true -DrsAutomationLevel FullyAutomated -Confirm:$false |Out-Null\n } catch {\n Write-Host -Foregroundcolor:red \"Could not set DRS Mode to automatic\"\n }\n}\n\nFunction RemoveRemovableMediaFromVMs($esxhost)\n{\n try {\n $esxhost | Get-VM | Where-Object {$_.PowerState -eq \"PoweredOn\"} | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False |Out-Null\n\n } catch {\n Write-Host -Foregroundcolor:red \"Could not get the vm objects from host.\"\n }\n}\n\nFunction EvacuateVMsFromHost($esxhost)\n{\n try {\n $esxhost | Set-VMHost -State Maintenance -Evacuate:$true -Confirm:$false |Out-Null\n } catch {\n Write-Host -Foregroundcolor:red \"Could not put host into maintenance mode\"\n }\n}\n\nFunction ShutDownHost($esxhost)\n{\n try {\n $esxhost | Stop-VMhost -Confirm:$false -Whatif\n } catch {\n Write-Host -Foregroundcolor:red \"Could not shut down host\"\n }\n}\n\n###### Main Program ######\nif ($SiteToShutdown -eq \"Allschwil\") {\n $hosts = @(\"bezhesx40.bechtlezh.ch\")\n\n} elseif ($SiteToShutdown -eq \"Pratteln\")\n{\n $hosts = @(\"bezhesx41.bechtlezh.ch\")\n}\n\nforeach ($esxhost in $hosts)\n{\n $cluster = (get-vmhost $esxhost).Parent\n SetDRStoAutomatic($cluster)\n\n $esxihost = Get-VMhost $esxhost\n RemoveRemovableMediaFromVMs($esxihost)\n EvacuateVMsFromHost($esxihost)\n ShutDownHost($esxihost)\n}\n\n# cleanup and removal of loaded VMware modules\nDisconnect-VIServer -Server $vCenter_server -Confirm:$false |Out-Null\nRemove-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue | Out-Null\nRemove-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null\n\n# write all error messages to the log file\nAdd-Content -Path $log_file -Value $Error\n```" } ], "status": { "corpus": 267, "alsoLike": [ { "ref": "services/platform", "score": "0.85" }, { "ref": "solutions/vmware/vmware-cloud-foundation", "score": "0.73" }, { "ref": "solutions/vmware/vmware-cloud-foundation/vcf-automation", "score": "0.73" } ] }}
apiVersion = "soultec.ch/v1"kind = "Post"[metadata]name = "powercli-automating-vm-shutdown-triggered-by-usv"locale = "en"[metadata.labels]author = "dario-doerflinger""capability/virtualization" = "1.37""capability/automation" = "1.78""vendor/vmware" = "0.88"[metadata.annotations]source = "blog-content/posts/en/powercli-automating-vm-shutdown-triggered-by-usv.md"route = "/en/insights/powercli-automating-vm-shutdown-triggered-by-usv/"schema = "/nerd/schema/posts.json"markdown = "/en/insights/powercli-automating-vm-shutdown-triggered-by-usv.md"[spec]title = "Automating VM Shutdown triggered by USV"date = 2017-07-21author = "dario-doerflinger"locale = "en"summary = "So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure."capabilities = ["virtualization", "automation"]vendors = ["vmware"]legacySlug = "powercli-automating-vm-shutdown-triggered-by-usv"migrated = 2026-08-24draft = false[[sections]]body = '''So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure.I started to write the following script, but it has not been finalized because some of the customer's engineers are on holidays. I will update this post as soon as the final script is ready.One thing to note: It uses the same VI Credential Store as my previous script to automate VM skeleton creation.Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).```powershell############################################################################################# Script name: EvacuateVMsFromUSV.ps1# Description: Evacuate all VMs from one site in a active-active cluster and shut down the Hosts# Version: 1.0# Date: 20.07.2017# Author: Dario Doerflinger (virtualfrog.wordpress.com)# History: 20.07.2017 - First tested release############################################################################################# Example: # e.g.: .\EvacuateVMsFromUSV.ps1 -SiteToShutdown Allschwilparam ( [string]$SiteToShutdown # Identifier of site)$vCenter_server = "bezhvcs03.bechtlezh.ch"# clear global ERROR variable$Error.Clear()# import vmware related modules, get the credentials and connect to the vCenter serverImport-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-NullImport-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue |Out-Null$creds = Get-VICredentialStoreItem -file "C:\Users\Administrator\Desktop\login.creds"Connect-VIServer -Server $vCenter_server -User $creds.User -Password $creds.Password |Out-Null# define global variables$current_date = $(Get-Date -format "dd.MM.yyyy HH:mm:ss")$log_file = "C:\Users\Administrator\Desktop\\log_$(Get-Date -format "yyyyMMdd").txt"Function SetDRStoAutomatic ($cluster){ try { $cluster | Set-Cluster -DrsEnabled:$true -DrsAutomationLevel FullyAutomated -Confirm:$false |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not set DRS Mode to automatic" }}Function RemoveRemovableMediaFromVMs($esxhost){ try { $esxhost | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not get the vm objects from host." }}Function EvacuateVMsFromHost($esxhost){ try { $esxhost | Set-VMHost -State Maintenance -Evacuate:$true -Confirm:$false |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not put host into maintenance mode" }}Function ShutDownHost($esxhost){ try { $esxhost | Stop-VMhost -Confirm:$false -Whatif } catch { Write-Host -Foregroundcolor:red "Could not shut down host" }}###### Main Program ######if ($SiteToShutdown -eq "Allschwil") { $hosts = @("bezhesx40.bechtlezh.ch")} elseif ($SiteToShutdown -eq "Pratteln"){ $hosts = @("bezhesx41.bechtlezh.ch")}foreach ($esxhost in $hosts){ $cluster = (get-vmhost $esxhost).Parent SetDRStoAutomatic($cluster) $esxihost = Get-VMhost $esxhost RemoveRemovableMediaFromVMs($esxihost) EvacuateVMsFromHost($esxihost) ShutDownHost($esxihost)}# cleanup and removal of loaded VMware modulesDisconnect-VIServer -Server $vCenter_server -Confirm:$false |Out-NullRemove-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue | Out-NullRemove-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null# write all error messages to the log fileAdd-Content -Path $log_file -Value $Error```'''[status]corpus = 267[[status.alsoLike]]ref = "services/platform"score = "0.85"[[status.alsoLike]]ref = "solutions/vmware/vmware-cloud-foundation"score = "0.73"[[status.alsoLike]]ref = "solutions/vmware/vmware-cloud-foundation/vcf-automation"score = "0.73"
<?xml version="1.0" encoding="UTF-8"?><manifest kind="Post"> <apiVersion>soultec.ch/v1</apiVersion> <metadata> <name>powercli-automating-vm-shutdown-triggered-by-usv</name> <locale>en</locale> <labels> <author>dario-doerflinger</author> <entry key="capability/virtualization">1.37</entry> <entry key="capability/automation">1.78</entry> <entry key="vendor/vmware">0.88</entry> </labels> <annotations> <source>blog-content/posts/en/powercli-automating-vm-shutdown-triggered-by-usv.md</source> <route>/en/insights/powercli-automating-vm-shutdown-triggered-by-usv/</route> <schema>/nerd/schema/posts.json</schema> <markdown>/en/insights/powercli-automating-vm-shutdown-triggered-by-usv.md</markdown> </annotations> </metadata> <spec> <title>Automating VM Shutdown triggered by USV</title> <date>2017-07-21</date> <author>dario-doerflinger</author> <locale>en</locale> <summary>So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure.</summary> <capabilities> <item>virtualization</item> <item>automation</item> </capabilities> <vendors> <item>vmware</item> </vendors> <legacySlug>powercli-automating-vm-shutdown-triggered-by-usv</legacySlug> <migrated>2026-08-24</migrated> <draft>false</draft> </spec> <sections> <section> <body>So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure.I started to write the following script, but it has not been finalized because some of the customer's engineers are on holidays. I will update this post as soon as the final script is ready.One thing to note: It uses the same VI Credential Store as my previous script to automate VM skeleton creation.Update: this script is now published at [GitHub](https://github.com/virtualFrog/PowerCLI-Scripts).```powershell############################################################################################# Script name: EvacuateVMsFromUSV.ps1# Description: Evacuate all VMs from one site in a active-active cluster and shut down the Hosts# Version: 1.0# Date: 20.07.2017# Author: Dario Doerflinger (virtualfrog.wordpress.com)# History: 20.07.2017 - First tested release############################################################################################# Example: # e.g.: .\EvacuateVMsFromUSV.ps1 -SiteToShutdown Allschwilparam ( [string]$SiteToShutdown # Identifier of site)$vCenter_server = "bezhvcs03.bechtlezh.ch"# clear global ERROR variable$Error.Clear()# import vmware related modules, get the credentials and connect to the vCenter serverImport-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-NullImport-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue |Out-Null$creds = Get-VICredentialStoreItem -file "C:\Users\Administrator\Desktop\login.creds"Connect-VIServer -Server $vCenter_server -User $creds.User -Password $creds.Password |Out-Null# define global variables$current_date = $(Get-Date -format "dd.MM.yyyy HH:mm:ss")$log_file = "C:\Users\Administrator\Desktop\\log_$(Get-Date -format "yyyyMMdd").txt"Function SetDRStoAutomatic ($cluster){ try { $cluster | Set-Cluster -DrsEnabled:$true -DrsAutomationLevel FullyAutomated -Confirm:$false |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not set DRS Mode to automatic" }}Function RemoveRemovableMediaFromVMs($esxhost){ try { $esxhost | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not get the vm objects from host." }}Function EvacuateVMsFromHost($esxhost){ try { $esxhost | Set-VMHost -State Maintenance -Evacuate:$true -Confirm:$false |Out-Null } catch { Write-Host -Foregroundcolor:red "Could not put host into maintenance mode" }}Function ShutDownHost($esxhost){ try { $esxhost | Stop-VMhost -Confirm:$false -Whatif } catch { Write-Host -Foregroundcolor:red "Could not shut down host" }}###### Main Program ######if ($SiteToShutdown -eq "Allschwil") { $hosts = @("bezhesx40.bechtlezh.ch")} elseif ($SiteToShutdown -eq "Pratteln"){ $hosts = @("bezhesx41.bechtlezh.ch")}foreach ($esxhost in $hosts){ $cluster = (get-vmhost $esxhost).Parent SetDRStoAutomatic($cluster) $esxihost = Get-VMhost $esxhost RemoveRemovableMediaFromVMs($esxihost) EvacuateVMsFromHost($esxihost) ShutDownHost($esxihost)}# cleanup and removal of loaded VMware modulesDisconnect-VIServer -Server $vCenter_server -Confirm:$false |Out-NullRemove-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue | Out-NullRemove-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null# write all error messages to the log fileAdd-Content -Path $log_file -Value $Error``` </body> </section> </sections> <status> <corpus>267</corpus> <alsoLike> <item> <ref>services/platform</ref> <score>0.85</score> </item> <item> <ref>solutions/vmware/vmware-cloud-foundation</ref> <score>0.73</score> </item> <item> <ref>solutions/vmware/vmware-cloud-foundation/vcf-automation</ref> <score>0.73</score> </item> </alsoLike> </status></manifest>
Post · 2017-07-21

Automating VM Shutdown triggered by USV

So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure.

2017-07-21Date
Dario DörflingerAuthor
2Min read
Topics Virtualization 1.37 Automation 1.78
Vendors VMware 0.88

This post is from 2017. It stays online because people still look for it, but it describes the products as they were then.

So another customer had a requirement. They want their USV to trigger a script that moves all VMs from one datacenter to the other datacenter in case of a power failure.

I started to write the following script, but it has not been finalized because some of the customer’s engineers are on holidays. I will update this post as soon as the final script is ready.

One thing to note: It uses the same VI Credential Store as my previous script to automate VM skeleton creation.

Update: this script is now published at GitHub.


############################################################################################
# Script name:     EvacuateVMsFromUSV.ps1
# Description:     Evacuate all VMs from one site in a active-active cluster and shut down the Hosts
# Version:         1.0
# Date:            20.07.2017
# Author:          Dario Doerflinger (virtualfrog.wordpress.com)
# History:         20.07.2017 - First tested release
############################################################################################

# Example: # e.g.: .\EvacuateVMsFromUSV.ps1 -SiteToShutdown Allschwil

param (
    [string]$SiteToShutdown # Identifier of site
)
$vCenter_server = "bezhvcs03.bechtlezh.ch"
# clear global ERROR variable
$Error.Clear()

# import vmware related modules, get the credentials and connect to the vCenter server
Import-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null
Import-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue |Out-Null
$creds = Get-VICredentialStoreItem -file  "C:\Users\Administrator\Desktop\login.creds"
Connect-VIServer -Server $vCenter_server -User $creds.User -Password $creds.Password |Out-Null

# define global variables

$current_date = $(Get-Date -format "dd.MM.yyyy HH:mm:ss")
$log_file = "C:\Users\Administrator\Desktop\\log_$(Get-Date -format "yyyyMMdd").txt"

Function SetDRStoAutomatic ($cluster)
{
    try {
        $cluster | Set-Cluster -DrsEnabled:$true -DrsAutomationLevel FullyAutomated -Confirm:$false |Out-Null
    } catch {
        Write-Host -Foregroundcolor:red "Could not set DRS Mode to automatic"
    }
}

Function RemoveRemovableMediaFromVMs($esxhost)
{
    try {
        $esxhost | Get-VM | Where-Object {$_.PowerState -eq "PoweredOn"} | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False |Out-Null

    } catch {
        Write-Host -Foregroundcolor:red "Could not get the vm objects from host."
    }
}

Function EvacuateVMsFromHost($esxhost)
{
    try {
        $esxhost | Set-VMHost -State Maintenance -Evacuate:$true -Confirm:$false |Out-Null
    } catch {
        Write-Host -Foregroundcolor:red "Could not put host into maintenance mode"
    }
}

Function ShutDownHost($esxhost)
{
    try {
       $esxhost | Stop-VMhost -Confirm:$false -Whatif
    } catch {
        Write-Host -Foregroundcolor:red "Could not shut down host"
    }
}

###### Main Program ######
if ($SiteToShutdown -eq "Allschwil") {
    $hosts = @("bezhesx40.bechtlezh.ch")

} elseif ($SiteToShutdown -eq "Pratteln")
{
    $hosts = @("bezhesx41.bechtlezh.ch")
}

foreach ($esxhost in $hosts)
{
    $cluster = (get-vmhost $esxhost).Parent
    SetDRStoAutomatic($cluster)

    $esxihost = Get-VMhost $esxhost
    RemoveRemovableMediaFromVMs($esxihost)
    EvacuateVMsFromHost($esxihost)
    ShutDownHost($esxihost)
}

# cleanup and removal of loaded VMware modules
Disconnect-VIServer -Server $vCenter_server -Confirm:$false |Out-Null
Remove-Module -Name VMware.VimAutomation.Vds -ErrorAction SilentlyContinue | Out-Null
Remove-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue | Out-Null

# write all error messages to the log file
Add-Content -Path $log_file -Value $Error

You might also like