RASInsider
← Alle Artikel
16. März 2026 / PowerShell & Automatisierung / 2 Min. Lesezeit

Die Konfigurationssicherung von Parallels RAS mit PowerShell automatisieren

Die Konfigurationssicherung von Parallels RAS mit PowerShell automatisieren

Parallels RAS speichert seine gesamte Konfiguration in einer zentralen Datenbank auf dem Connection Broker: Veröffentlichungsregeln, Farm-Topologie, Sitzungsrichtlinien, Anpassungen der Oberfläche und mehr. Geht diese Konfiguration verloren — nach einem Broker-Ausfall, einem missglückten Update oder dem kompletten Neuaufbau eines Servers —, muss alles von Hand neu konfiguriert werden, was bei einer komplexen Umgebung mehrere Stunden dauern kann.

Mit dem Cmdlet Invoke-RASExportSettings aus dem PowerShell-SDK von Parallels RAS lässt sich die gesamte Konfiguration in eine .dat2-Datei exportieren, die jederzeit mit Invoke-RASImportSettings wiederhergestellt werden kann. Das in diesem Artikel vorgestellte Skript automatisiert diesen Export täglich und kümmert sich um die Aufbewahrung der Dateien.

Die Authentifizierung erfolgt über ein eigenes Domänenkonto svc_rasexport, dessen Passwort lokal mit der SecureString-API von PowerShell verschlüsselt in einer Anmeldedatendatei liegt. Die Sicherungen werden auf einer eigenen Netzwerkfreigabe \MSHOME-VEEAMRASBACKUP$ auf dem Veeam-Sicherungsserver abgelegt. Dieses Konto benötigt die Rolle RAS Administrator in der RAS-Farm — Power Administrator reicht nicht aus. In diesem Beispiel läuft das Skript direkt auf einem der Broker.

$ScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$LogFile = "$ScriptRootRASBackup_$(Get-Date -Format 'yyyy-MM').log"
$BackupShare = "\MSHOME-VEEAM\RASBACKUP$\$(Get-Date -Format 'dd-MM-yyyy').dat2"
$BrokerFQDN = $env:COMPUTERNAME
$ServiceAccount = "svc_rasexport@$($env:USERDNSDOMAIN)"
$CredentialStore = "$ScriptRootsvc_rasexport.cred"
$EncryptionKey = (1..32)
$RetentionDays = 30

function Write-Log {
param([string]$Message, [string]$Level = "INFO")
$Entry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [$Level] $Message"
Add-Content -Path $LogFile -Value $Entry
switch ($Level) {
"ERROR" { Write-Host $Entry -ForegroundColor Red }
"WARN" { Write-Host $Entry -ForegroundColor Yellow }
default { Write-Host $Entry }
}
}

function Get-RASCredential {
if (-not (Test-Path $CredentialStore)) {
Write-Log "Credential store not found: $CredentialStore" "ERROR"
Write-Log "Run once to initialize: Read-Host -AsSecureString | ConvertFrom-SecureString -Key (1..32) | Set-Content '$CredentialStore'" "WARN"
exit 1
}
try {
$SecurePassword = Get-Content $CredentialStore | ConvertTo-SecureString -Key $EncryptionKey
return New-Object System.Management.Automation.PSCredential($ServiceAccount, $SecurePassword)
}
catch {
Write-Log "Failed to decrypt credential: $_" "ERROR"
exit 1
}
}

function Connect-RASBroker {
$Credential = Get-RASCredential
try {
Write-Log "Connecting to RAS broker $BrokerFQDN as $ServiceAccount"
New-RASSession -Server $BrokerFQDN -Username $Credential.UserName -Password $Credential.Password
Write-Log "RAS session established"
return $true
}
catch {
Write-Log "Failed to connect to RAS broker: $_" "ERROR"
return $false
}
}

function Invoke-RASBackup {
$BackupDir = Split-Path -Parent $BackupShare
if (-not (Test-Path $BackupDir)) {
New-Item -ItemType Directory -Path $BackupDir -Force | Out-Null
}
try {
Write-Log "Exporting RAS settings to $BackupShare"
Invoke-RASExportSettings $BackupShare
Write-Log "Export completed successfully"
}
catch {
Write-Log "Export failed: $_" "ERROR"
exit 1
}
finally {
Remove-RASSession -ErrorAction SilentlyContinue
Write-Log "RAS session closed"
}
}

function Invoke-BackupRetention {
$BackupDir = Split-Path -Parent $BackupShare
Get-ChildItem -Path $BackupDir -Filter "*.dat2" |
Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-$RetentionDays) } |
ForEach-Object {
Remove-Item $_.FullName -Force
Write-Log "Removed expired backup: $($_.Name)" "WARN"
}
}

Write-Log "Backup started"

if (Connect-RASBroker) {
Invoke-RASBackup
Invoke-BackupRetention
Write-Log "Backup completed"
} else {
Write-Log "Backup failed" "ERROR"
exit 1
}

Um die Anmeldedatendatei zu initialisieren, führen Sie das folgende Skript einmalig interaktiv auf dem Broker aus, und zwar mit dem Konto, unter dem die geplante Aufgabe laufen wird:

$CredentialStore = "$PSScriptRootsvc_rasexport.cred"
$EncryptionKey = (1..32)

Read-Host -AsSecureString -Prompt "Password for svc_rasexport" |
ConvertFrom-SecureString -Key $EncryptionKey |
Set-Content $CredentialStore

Write-Host "Credential store created: $CredentialStore"

Derzeit ist es nicht möglich, dieses Skript mit einem gMSA-Konto auszuführen. Das Cmdlet New-RASSession erfordert einen expliziten Parameter -Password vom Typ SecureString, was mit der Passwortverwaltung von gMSA-Konten nicht vereinbar ist. Ein klassisches Dienstkonto mit verschlüsselter Passwortdatei bleibt die einzige praktikable Lösung.

RASInsider in den Google-Schlagzeilen bevorzugt sehen?RASInsider als bevorzugte Quelle bei Google hinzufügen

War dieser Artikel hilfreich?