You could optimise the shutdownVM function like this.
Only one Get-VM and Shutdown-VMGuest and Stop-VM on multiple VMs in 1 call.
function shutdownVM($prioTag)
{
$vms = Get-VM -Tag $prioTag
$graceful = $vms | where {$_.ExtensionData.Guest.ToolsStatus -eq "toolsOk"}
if($graceful){
Write-Host "Shutting down $($graceful.Count) vms!"
Shutdown-VMGuest -VM $graceful -Confirm:$false | Out-Null
}
$hard = $vms | where {$_.PowerState -eq "poweredon"} | where {$_.ExtensionData.Guest.ToolsStatus -ne "toolsOk"}
if($hard){
Write-Host "Tools not responding. Killing $($hard.Count) vms!"
Stop-VM -VM $hard -Kill -RunAsync -Confirm:$false | Out-Null
}
}