$url = 'https://gist.githubusercontent.com/jeremy-jameson' `
+ '/913c11a4550efe428bbe7d6e1c82c955/raw'
Invoke-WebRequest `
-UseBasicParsing `
-Uri $url `
-OutFile 'C:\NotBackedUp\Temp\Cluster VMs.csv'
Note:
The previous PowerShell command downloads a sample list of virtual machines running on a cluster with "startup order" to a file. You will need to modify the list accordingly for your environment.
Import-Csv 'C:\NotBackedUp\Temp\Cluster VMs.csv' |
sort @{ e = {$_.StartupOrder -as [int]} } |
where { $_.StartupOrder -ne 0 } |
foreach {
$vm = Get-SCVirtualMachine -Name $_.Name
If ($vm)
{
If ($vm.VirtualMachineState -ne 'Running')
{
Write-Verbose "Starting VM ($($vm.Name))..."
Start-SCVirtualMachine $vm |
select Name, MostRecentTask, MostRecentTaskUIState
Start-Sleep -Seconds 30
}
}
}
Import-Csv 'C:\NotBackedUp\Temp\Cluster VMs.csv' |
sort @{ e = {$_.StartupOrder -as [int]} } -Descending |
foreach {
$vm = Get-SCVirtualMachine -Name $_.Name
If ($vm)
{
If ($vm.VirtualMachineState -eq 'Running')
{
Write-Verbose "Stopping VM ($($vm.Name))..."
Stop-SCVirtualMachine $vm |
select Name, MostRecentTask, MostRecentTaskUIState
}
}
}
Import-Csv 'C:\NotBackedUp\Temp\Cluster VMs.csv' |
sort @{ e = {$_.StartupOrder -as [int]} } -Descending |
foreach {
$vm = Get-SCVirtualMachine -Name $_.Name |
where { $_.IsHighlyAvailable -eq $true }
If ($vm)
{
If ($vm.VirtualMachineState -eq 'Running')
{
Write-Verbose "Stopping VM ($($vm.Name))..."
Stop-SCVirtualMachine $vm |
select Name, MostRecentTask, MostRecentTaskUIState
}
}
}
Note:
This is used when it is necessary to take the cluster shared volumes offline -- e.g. to upgrade the NAS (Network Attached Storage).