sync
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
# shutdown VDI via GUI
|
||||
|
||||
# Get All VMs 5 minutes
|
||||
$AllVMs = Get-Datacenter -Name Primary* | Get-Cluster | Where-Object Name -ne MGMT1 | Get-VM
|
||||
$AllVMTags = $AllVMs | Get-TagAssignment -Category DTAP, StartupPriority # 3.5 minutes
|
||||
|
||||
# while that runs, vmotion des-cad rabbitmq ??? contact Shawn F for Solarwinds
|
||||
|
||||
<# retag VMware VMs to Priority 0
|
||||
get-vm -name itdvm* | Get-TagAssignment -Category StartupPriority | Remove-TagAssignment -Confirm:$false
|
||||
$Tag = Get-Tag -Category StartupPriority -Name 0 -Server itdvmvc1.nd.gov
|
||||
get-vm -name itdvm* | Get-TagAssignment -Category StartupPriority | Remove-TagAssignment -Confirm:$false
|
||||
|
||||
Get-VM -name itdvm* | ForEach-Object{
|
||||
$ViServer=$_.Uid.split('@')[1].split(':')[0]
|
||||
$Tag = Get-Tag -Category StartupPriority -Name 0 -Server $ViServer
|
||||
$_ | New-TagAssignment -Tag $Tag
|
||||
}
|
||||
#>
|
||||
|
||||
$AllVMsWithTags = [System.Collections.ArrayList]@()
|
||||
|
||||
ForEach ($VM in $AllVMs) {
|
||||
$obj = [PSCustomObject]@{
|
||||
'VMName' = $VM.Name;
|
||||
'DTAP' = ($AllVMTags | Where-Object { $_.Entity.Name -eq $VM.Name -and $_.Tag.Category.Name -eq 'DTAP' }).Tag.Name
|
||||
'StartupPriority' = ($AllVMTags | Where-Object { $_.Entity.Name -eq $VM.Name -and $_.Tag.Category.Name -eq 'StartupPriority' }).Tag.Name
|
||||
}
|
||||
|
||||
#Write-Output $obj
|
||||
$null = $AllVMsWithTags.Add($obj)
|
||||
}
|
||||
|
||||
#Populate variables
|
||||
$AllTest5 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 5 -and $_.DTAP -eq 'Test'}
|
||||
$AllTest4 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 4 -and $_.DTAP -eq 'Test'}
|
||||
$AllTest3 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 3 -and $_.DTAP -eq 'Test'}
|
||||
$AllTest2 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 2 -and $_.DTAP -eq 'Test'}
|
||||
$AllTest1 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 1 -and $_.DTAP -eq 'Test'}
|
||||
|
||||
<#
|
||||
$AllProd5 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 5 -and $_.DTAP -eq 'Production'}
|
||||
$AllProd4 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 4 -and $_.DTAP -eq 'Production'}
|
||||
$AllProd3 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 3 -and $_.DTAP -eq 'Production'}
|
||||
$AllProd2 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 2 -and $_.DTAP -eq 'Production'}
|
||||
$AllProd1 = $AllVMsWithTags | Where-Object {$_.StartupPriority -eq 1 -and $_.DTAP -eq 'Production'}
|
||||
#>
|
||||
|
||||
# shutdown VMs by variable group
|
||||
ForEach($VM in $AllTest5){
|
||||
Get-VM -Name $VM.VMName -Server itdvmvc1.nd.gov #|Stop-VMGuest
|
||||
}
|
||||
|
||||
# monitor the shutdown
|
||||
Get-Datacenter -Name Primary* | Get-VM -Name $AllTest5.VMName
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# disable all host alarms and put all hosts into maintenance
|
||||
$AllVMHosts = Get-Datacenter -Name Primary* | Get-Cluster | Where-Object Name -ne MGMT1 | Get-VMHost
|
||||
foreach ($VMHostName in $AllVMHosts) {
|
||||
Write-Warning -Message ("Start $VMHostName")
|
||||
$GetVMHost = Get-VMHost $VMHostName
|
||||
$VIServer = $GetVMHost.Uid.Split('@')[1].Split(':')[0]
|
||||
$alarmMgr = Get-View AlarmManager -Server $VIServer
|
||||
$alarmEnabled = $GetVMHost.ExtensionData.AlarmActionsEnabled
|
||||
if ($alarmEnabled -eq $true) {
|
||||
$alarmMgr.EnableAlarmActions($GetVMHost.ExtensionData.MoRef, $false)
|
||||
}
|
||||
}
|
||||
# maintenance manually in GUI *******************************
|
||||
# shutdown manually in GUI *******************************
|
||||
Reference in New Issue
Block a user