Files
syno-scripts/Powershell/Shutdown/Modules/Shtudown.psm1
T

63 lines
1.2 KiB
PowerShell
Executable File

function Stop-VMsByGroup {
param($VMGroups)
```
$groups = $VMGroups.Gruppe | Select-Object -Unique
foreach ($g in $groups) {
$names = ($VMGroups | Where-Object Gruppe -eq $g).Server
$vms = Get-VM | Where-Object { $names -contains $_.Name }
foreach ($vm in $vms) {
if ($vm.PowerState -eq "PoweredOn") {
Shutdown-VMGuest -VM $vm -Confirm:$false -ErrorAction SilentlyContinue
}
}
Start-Sleep -Seconds 60
}
```
}
function Stop-UnknownVMs {
param($VMGroups, $ExcludeRegex)
```
$vms = Get-VM | Where-Object {
($VMGroups.Server -notcontains $_.Name) -and
($_.Name -notmatch $ExcludeRegex)
}
foreach ($vm in $vms) {
if ($vm.PowerState -eq "PoweredOn") {
Shutdown-VMGuest -VM $vm -Confirm:$false -ErrorAction SilentlyContinue
}
}
```
}
function Stop-ClusterSafe {
param(
[string]$Cluster,
[string]$Reason
)
```
Stop-VsanCluster -Cluster $Cluster -PowerOffReason $Reason -ErrorAction Stop | Out-Null
```
}
function Stop-VMHostSafe {
param([string]$VMHost)
```
Set-VMHost -VMHost $VMHost -State Maintenance -Confirm:$false | Out-Null
Stop-VMHost -VMHost $VMHost -Confirm:$false -ErrorAction Stop | Out-Null
```
}