Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Created December 18, 2019 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vMarkusK/54ab613871a02a17c35733342ad55a1c to your computer and use it in GitHub Desktop.
Save vMarkusK/54ab613871a02a17c35733342ad55a1c to your computer and use it in GitHub Desktop.
# Parameters
$ClusterName = "win"
$DatastoreName = "scratch00"
# Get Cluster
$Cluster = Get-Cluster -Name $ClusterName
# Disable VM DRS Roles
$Cluster | Get-DrsRule | Set-DrsRule -Enabled:$false
# Disabel HA Admissioin Control
$Trash = $Cluster | Set-Cluster -HAAdmissionControlEnabled:$false -Confirm:$False
foreach ($VMHost in $($Cluster | Get-VMHost )) {
$Shortname = ($VMHost.Name.Split("."))[0]
$Datastore = $VMhost | Get-Datastore -Name $DatastoreName
if ($Datastore){
$DatastoreDriveName = "HostStore_" + $Shortname
$Datastore | New-DatastoreDrive -Name $DatastoreDriveName | Out-Null
New-Item -Path $($DatastoreDriveName + ":\.locker-$Shortname") -ItemType Directory -Confirm:$false -Force
Remove-PSDrive -Name $DatastoreDriveName
$VMHost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" | Set-AdvancedSetting -Value "/vmfs/volumes/$($Datastore.Name)/.locker-$Shortname" -Confirm:$false
$Trash = $VMHost | Set-VMHost -State Maintenance -Evacuate -Confirm:$false
$VMHost | Restart-VMHost -Confirm:$false
"$($VMHost.Name) is Restarting"
do {
Start-Sleep 5
$ServerState = (Get-VMHost $VMHost.Name).ConnectionState
}
while ($ServerState -ne "NotResponding")
"$($VMHost.Name) is Down"
# Wait for server to reboot
do {
Start-Sleep 15
$ServerState = (Get-VMHost $VMHost.Name).ConnectionState
}
while ($ServerState -ne "Maintenance")
"$($VMHost.Name) is Up"
$Trash = $VMHost | Set-VMHost -State Connected -Confirm:$false
}
else{ throw "No Datastore Found"}
}
$Cluster | Get-DrsRule | Set-DrsRule -Enabled:$true -ErrorAction SilentlyContinue
$Trash = $Cluster | Set-Cluster -HAAdmissionControlEnabled:$true -Confirm:$False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment