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
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
$Config = @{
Cluster = "INFRA"
CSVGroups = "C:\\Shutdown\\Input.csv"
LogPath = "C:\\Shutdown"
VCenterServer = $null
StorageSystem = $null
```
CredFiles = @{
vCenter = "C:\Shutdown\vcenter-cred.xml"
storage = "C:\Shutdown\storage.xml"
}
Tools = @{
Plink = "C:\Program Files (x86)\PuTTY\plink.exe"
}
```
}
+44
View File
@@ -0,0 +1,44 @@
# Config laden
. "C:\\Shutdown\\Config.ps1"
# Module laden
Import-Module ".\\Modules\\Logging.psm1"
Import-Module ".\\Modules\\Credentials.psm1"
Import-Module ".\\Modules\\VCenter.psm1"
Import-Module ".\\Modules\\Shutdown.psm1"
# Logging
$LogFile = New-LogFile $Config.LogPath
Start-Transcript -Path $LogFile -Append
Write-Host "[INFO] Shutdown gestartet"
# Credentials
$vCenterCred = Get-CredentialFromFile $Config.CredFiles.vCenter
$storageCred = Get-CredentialFromFile $[Config.CredFiles.storage](http://Config.CredFiles.storage)
# vCenter Verbindung
Connect-ToVCenter -Server $Config.VCenterServer -Credential $vCenterCred
# CSV laden
$VMGroups = Import-Csv $Config.CSVGroups -Delimiter ";"
$VMGroups | ForEach-Object { $*.Gruppe = [int]$*.Gruppe }
$VMGroups = $VMGroups | Sort-Object Gruppe
# Shutdown Pipeline
Stop-UnknownVMs -VMGroups $VMGroups -ExcludeRegex "vCLS|vSAN"
Stop-VMsByGroup -VMGroups $VMGroups
Stop-VMHostSafe -VMHost "GWHost01"
Stop-ClusterSafe -Cluster $Config.Cluster -Reason "Automated Shutdown"
Stop-Transcript
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+12
View File
@@ -0,0 +1,12 @@
function Get-CredentialFromFile {
param([string]$Path)
```
if (!(Test-Path $Path)) {
throw "Credential file not found: $Path"
}
return Import-Clixml -Path $Path
```
}
+25
View File
@@ -0,0 +1,25 @@
function New-LogFile {
param($LogPath)
```
if (!(Test-Path $LogPath)) {
New-Item -ItemType Directory -Path $LogPath | Out-Null
}
return Join-Path $LogPath ("Shutdown_{0}.log" -f (Get-Date -Format "yyyy-MM-dd_HH-mm-ss"))
```
}
function Write-Log {
param(
[string]$Message,
[string]$Level = "INFO"
)
```
$line = "[{0}] {1}" -f $Level, $Message
Write-Host $line
```
}
+63
View File
@@ -0,0 +1,63 @@
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
```
}
+15
View File
@@ -0,0 +1,15 @@
function Connect-ToVCenter {
param(
[string]$Server,
[pscredential]$Credential
)
```
Import-Module VMware.PowerCLI -ErrorAction Stop
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
Connect-VIServer -Server $Server -Credential $Credential -ErrorAction Stop | Out-Null
```
}