Version 1.0 of Configure
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
function Get-HyperVInventory {
|
||||
param([Parameter(Mandatory)][string]$Server)
|
||||
|
||||
foreach($Name in @("Get-VBRServer", "Find-VBRHvEntity")) {
|
||||
if($null -eq (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
||||
throw "Veeam-Befehl nicht verfügbar: $Name"
|
||||
}
|
||||
}
|
||||
|
||||
$VBRServer = Get-VBRServer -Name $Server |
|
||||
Where-Object { $_.Type -in @("HvServer", "HvCluster", "Scvmm") } |
|
||||
Select-Object -First 1
|
||||
|
||||
if($null -eq $VBRServer) {
|
||||
throw "Hyper-V-Server ist in Veeam nicht registriert: $Server"
|
||||
}
|
||||
|
||||
@(Find-VBRHvEntity -Server $VBRServer -HostsAndVMs |
|
||||
Where-Object { $_.Type -match "Vm" } |
|
||||
Select-Object -ExpandProperty Name -Unique)
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Get-HyperVInventory
|
||||
@@ -0,0 +1,75 @@
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
function Get-ProxmoxInventory {
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Server,
|
||||
[Parameter(Mandatory)][PSCredential]$ApiCredential,
|
||||
[switch]$TrustSelfSignedCertificate
|
||||
)
|
||||
|
||||
$Secret = $ApiCredential.GetNetworkCredential().Password
|
||||
$Headers = @{ Authorization = "PVEAPIToken=$($ApiCredential.UserName)=$Secret" }
|
||||
$Uri = "https://$Server`:8006/api2/json/cluster/resources?type=vm"
|
||||
$PreviousProtocol = [Net.ServicePointManager]::SecurityProtocol
|
||||
$PreviousCertificatePolicy = $null
|
||||
$CertificatePolicyChanged = $false
|
||||
$RequestParameters = @{
|
||||
Method = "Get"
|
||||
Uri = $Uri
|
||||
Headers = $Headers
|
||||
ErrorAction = "Stop"
|
||||
}
|
||||
|
||||
try {
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
if($TrustSelfSignedCertificate) {
|
||||
$InvokeRestMethod = Get-Command Invoke-RestMethod -ErrorAction Stop
|
||||
|
||||
if($InvokeRestMethod.Parameters.ContainsKey("SkipCertificateCheck")) {
|
||||
$RequestParameters["SkipCertificateCheck"] = $true
|
||||
}
|
||||
else {
|
||||
if($null -eq ("TemporaryTrustAllCertificatePolicy" -as [type])) {
|
||||
Add-Type -TypeDefinition @"
|
||||
using System.Net;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
public sealed class TemporaryTrustAllCertificatePolicy : ICertificatePolicy
|
||||
{
|
||||
public bool CheckValidationResult(
|
||||
ServicePoint servicePoint,
|
||||
X509Certificate certificate,
|
||||
WebRequest request,
|
||||
int certificateProblem)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
$PreviousCertificatePolicy = [Net.ServicePointManager]::CertificatePolicy
|
||||
[Net.ServicePointManager]::CertificatePolicy =
|
||||
New-Object TemporaryTrustAllCertificatePolicy
|
||||
$CertificatePolicyChanged = $true
|
||||
}
|
||||
}
|
||||
|
||||
$Response = Invoke-RestMethod @RequestParameters
|
||||
@($Response.data |
|
||||
Where-Object { $_.type -eq "qemu" } |
|
||||
Select-Object -ExpandProperty name -Unique)
|
||||
}
|
||||
finally {
|
||||
[Net.ServicePointManager]::SecurityProtocol = $PreviousProtocol
|
||||
if($CertificatePolicyChanged) {
|
||||
[Net.ServicePointManager]::CertificatePolicy = $PreviousCertificatePolicy
|
||||
}
|
||||
$Secret = $null
|
||||
$Headers = $null
|
||||
$RequestParameters = $null
|
||||
}
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Get-ProxmoxInventory
|
||||
@@ -0,0 +1,25 @@
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
function Get-VMwareInventory {
|
||||
param([Parameter(Mandatory)][string]$Server)
|
||||
|
||||
foreach($Name in @("Get-VBRServer", "Find-VBRViEntity")) {
|
||||
if($null -eq (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
||||
throw "Veeam-Befehl nicht verfügbar: $Name"
|
||||
}
|
||||
}
|
||||
|
||||
$VBRServer = Get-VBRServer -Name $Server |
|
||||
Where-Object { $_.Type -in @("VC", "ESXi", "ESX") } |
|
||||
Select-Object -First 1
|
||||
|
||||
if($null -eq $VBRServer) {
|
||||
throw "VMware-Server ist in Veeam nicht registriert: $Server"
|
||||
}
|
||||
|
||||
@(Find-VBRViEntity -Server $VBRServer -VMsAndTemplates |
|
||||
Where-Object { $_.Type -match "Vm" } |
|
||||
Select-Object -ExpandProperty Name -Unique)
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function Get-VMwareInventory
|
||||
@@ -0,0 +1,53 @@
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
function New-AlphabeticalSchedulePlan {
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$JobName,
|
||||
[AllowEmptyCollection()][string[]]$VirtualMachines = @(),
|
||||
[Parameter(Mandatory)][object[]]$ScheduleGroups
|
||||
)
|
||||
|
||||
$Results = @()
|
||||
foreach($Group in $ScheduleGroups) {
|
||||
foreach($Property in @("Name", "From", "To", "Time")) {
|
||||
if($Group.PSObject.Properties.Name -notcontains $Property) {
|
||||
throw "Zeitplangruppe enthält nicht den Pflichtwert '$Property'."
|
||||
}
|
||||
}
|
||||
|
||||
if([string]$Group.Time -notmatch '^(?:[01]\d|2[0-3]):[0-5]\d$') {
|
||||
throw "Ungültige Uhrzeit in Gruppe '$($Group.Name)': $($Group.Time)"
|
||||
}
|
||||
|
||||
$Other = ([string]$Group.From -eq "Other") -and ([string]$Group.To -eq "Other")
|
||||
$Members = @()
|
||||
|
||||
foreach($VM in $VirtualMachines) {
|
||||
if([string]::IsNullOrWhiteSpace($VM)) { continue }
|
||||
$Initial = $VM.Substring(0, 1).ToUpperInvariant()
|
||||
$Letter = $Initial -match '^[A-Z]$'
|
||||
$Match = $Other -and !$Letter
|
||||
|
||||
if(!$Other -and $Letter) {
|
||||
$From = ([string]$Group.From).ToUpperInvariant()
|
||||
$To = ([string]$Group.To).ToUpperInvariant()
|
||||
$Match = ($Initial -ge $From) -and ($Initial -le $To)
|
||||
}
|
||||
|
||||
if($Match) { $Members += $VM }
|
||||
}
|
||||
|
||||
if($Members.Count -gt 0) {
|
||||
$Results += [PSCustomObject]@{
|
||||
Group = [string]$Group.Name
|
||||
JobName = "{0}-{1}" -f $JobName, $Group.Name
|
||||
Time = [string]$Group.Time
|
||||
VirtualMachines = $Members
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $Results
|
||||
}
|
||||
|
||||
Export-ModuleMember -Function New-AlphabeticalSchedulePlan
|
||||
Reference in New Issue
Block a user