Initialer Import der Synology Scripts

This commit is contained in:
root
2026-08-05 08:43:57 +02:00
commit 5e32a7c411
404 changed files with 79932 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
function Stop-VMParallel {
param([array]$VMs, [int]$Throttle = 8)
```
$VMs | ForEach-Object -Parallel {
Import-Module VMware.PowerCLI -ErrorAction SilentlyContinue
$vm = $_
if ($vm.PowerState -ne "PoweredOn") { return }
try {
Shutdown-VMGuest -VM $vm -Confirm:$false -ErrorAction Stop
}
catch {
Write-Host "[ERROR] VM failed: $($vm.Name)"
}
} -ThrottleLimit $Throttle
```
}
function Stop-VMsByGroup {
param($VMGroups)
```
$groups = $VMGroups.Gruppe | Sort-Object -Unique
foreach ($g in $groups) {
$names = ($VMGroups | Where-Object Gruppe -eq $g).Server
$vms = Get-VM | Where-Object { $names -contains $_.Name }
if ($vms) {
Stop-VMParallel -VMs $vms
Start-Sleep 30
}
}
```
}
function Stop-UnknownVMs {
param($VMGroups, $ExcludeRegex)
```
$vms = Get-VM | Where-Object {
($VMGroups.Server -notcontains $_.Name) -and
($_.Name -notmatch $ExcludeRegex)
}
if ($vms) {
Stop-VMParallel -VMs $vms
}
```
}
function Stop-ClusterSafe {
param([string]$Cluster, [string]$Reason)
```
Invoke-Retry -Name "Cluster shutdown" -Action {
Stop-VsanCluster -Cluster $Cluster -PowerOffReason $Reason -ErrorAction Stop | Out-Null
}
```
}