69 lines
1.6 KiB
PowerShell
69 lines
1.6 KiB
PowerShell
# in separate terminal
|
|
$MgmtHosts = @(
|
|
"itdvmbismgmt02.nd.gov",
|
|
"itdvmbismgmt03.nd.gov",
|
|
"itdvmmdnmgmt01.nd.gov",
|
|
"itdvmmdnmgmt02.nd.gov"
|
|
)
|
|
|
|
Connect-ITDvCenter -Credential $PrvCred
|
|
|
|
# Disable lockdown
|
|
ForEach($VMHostName in $MgmtHosts){
|
|
(Get-VMHost $VMHostName | Get-View).ExitLockdownMode()
|
|
}
|
|
|
|
Disconnect-ITDvCenter
|
|
|
|
########## start from a fresh PowerShell session
|
|
# get credentials and connect
|
|
ForEach($VMHostName in $MgmtHosts){
|
|
$Creds = $null
|
|
$Creds = Get-ITDPassword -Title $VMHostName -UserName root -Credential $PrvCred
|
|
Connect-VIServer -Server $VMHostName -Credential $Creds
|
|
}
|
|
|
|
# verify direct host vi server connection
|
|
$global:DefaultVIServers
|
|
|
|
# VM array
|
|
$VMarray = @(
|
|
"itdvmvc1.nd.gov",
|
|
"itdvmvc2.nd.gov",
|
|
"itdvmvra1.nd.gov",
|
|
"itdvmvra2.nd.gov",
|
|
"itdvmvrsmdn1.nd.gov",
|
|
"itdvmvrsmdn2.nd.gov",
|
|
"itdvmsrm1.nd.gov",
|
|
"itdvmsrm2.nd.gov"
|
|
)
|
|
|
|
# get all VMs
|
|
$VMs = Get-VM -Name $VMarray | Sort-Object Name
|
|
|
|
# shutdown VMs
|
|
$VMs | Get-VMGuest | Stop-VMGuest -Confirm:$false
|
|
|
|
# wait for VMs to power off
|
|
Get-VM -Name $VMarray | Sort-Object Name
|
|
|
|
# take snapshot of all VMs
|
|
$VMs | ForEach-Object {$_ | New-Snapshot -Name "Before-VR&SRM 9.0 upgrade"}
|
|
|
|
# confirm all snapshots were taken
|
|
Get-VM -Name $VMarray | Get-Snapshot | Select VM,Name | sort-object VM
|
|
|
|
# power on all VMs
|
|
Get-VM -Name $VMarray | Start-VM
|
|
|
|
|
|
|
|
Disconnect-VIServer -Server * -Confirm:$false
|
|
|
|
# disconnect all host direct connections
|
|
Disconnect-VIServer * -Confirm:$false
|
|
|
|
# Enable Lockdown
|
|
ForEach($VMHostName in $MgmtHosts){
|
|
(Get-VMHost $VMHostName | Get-View).EnterLockdownMode()
|
|
} |