Initialer Import der Synology Scripts
This commit is contained in:
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
+12
@@ -0,0 +1,12 @@
|
||||
function Get-CredentialFromFile {
|
||||
param([string]$Path)
|
||||
|
||||
```
|
||||
if (!(Test-Path $Path)) {
|
||||
throw "Missing credential file: $Path"
|
||||
}
|
||||
|
||||
Import-Clixml -Path $Path
|
||||
```
|
||||
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
enum LogLevel {
|
||||
INFO
|
||||
WARN
|
||||
ERROR
|
||||
DEBUG
|
||||
}
|
||||
|
||||
function Write-Log {
|
||||
param(
|
||||
[string]$Message,
|
||||
[LogLevel]$Level = [LogLevel]::INFO
|
||||
)
|
||||
|
||||
```
|
||||
$ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||
$line = "[$ts][$Level] $Message"
|
||||
|
||||
switch ($Level) {
|
||||
"INFO" { Write-Host $line -ForegroundColor Gray }
|
||||
"WARN" { Write-Host $line -ForegroundColor Yellow }
|
||||
"ERROR" { Write-Host $line -ForegroundColor Red }
|
||||
"DEBUG" { Write-Host $line -ForegroundColor DarkGray }
|
||||
}
|
||||
```
|
||||
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
function Invoke-Retry {
|
||||
param(
|
||||
[scriptblock]$Action,
|
||||
[int]$Retries = 3,
|
||||
[int]$DelaySeconds = 5,
|
||||
[string]$Name = "Operation"
|
||||
)
|
||||
|
||||
```
|
||||
for ($i = 1; $i -le $Retries; $i++) {
|
||||
try {
|
||||
return & $Action
|
||||
}
|
||||
catch {
|
||||
Write-Log "$Name failed ($i/$Retries): $($_.Exception.Message)" -Level WARN
|
||||
|
||||
if ($i -eq $Retries) { throw }
|
||||
|
||||
Start-Sleep $DelaySeconds
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
}
|
||||
Executable
+68
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
function Connect-ToVCenter {
|
||||
param(
|
||||
[string]$Server,
|
||||
[pscredential]$Credential
|
||||
)
|
||||
|
||||
```
|
||||
Import-Module VMware.PowerCLI -ErrorAction Stop
|
||||
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
|
||||
|
||||
Invoke-Retry -Name "vCenter connect" -Action {
|
||||
Connect-VIServer -Server $Server -Credential $Credential -ErrorAction Stop | Out-Null
|
||||
}
|
||||
```
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user