Created
December 18, 2019 13:29
-
-
Save vMarkusK/54ab613871a02a17c35733342ad55a1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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