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
+12
@@ -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
|
||||
```
|
||||
|
||||
}
|
||||
Executable
+25
@@ -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
|
||||
```
|
||||
|
||||
}
|
||||
Executable
+63
@@ -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
|
||||
```
|
||||
|
||||
}
|
||||
Executable
+15
@@ -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
|
||||
```
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user