Skip to content

Instantly share code, notes, and snippets.

@eugrus
Created July 14, 2026 17:03
Show Gist options
  • Select an option

  • Save eugrus/b8ea2ce441d4416b30dfad4aeb8f2297 to your computer and use it in GitHub Desktop.

Select an option

Save eugrus/b8ea2ce441d4416b30dfad4aeb8f2297 to your computer and use it in GitHub Desktop.
param(
[Parameter(Mandatory = $true, Position = 0)]
[string]$OvpnFile,
[Parameter(Mandatory = $true, Position = 1)]
[string]$CaFile,
[Parameter(Mandatory = $true, Position = 2)]
[string]$CertFile,
[Parameter(Mandatory = $true, Position = 3)]
[string]$KeyFile,
[Parameter(Position = 4)]
[string]$OutputFile
)
if (-not $OutputFile) {
$directory = Split-Path $OvpnFile -Parent
$basename = [System.IO.Path]::GetFileNameWithoutExtension($OvpnFile)
$OutputFile = Join-Path $directory "${basename}_unified.ovpn"
}
# OVPN-Datei lesen und externe Zertifikatsreferenzen entfernen
$ovpnContent = Get-Content $OvpnFile | Where-Object {
$_ -notmatch '^ca\s+' -and
$_ -notmatch '^cert\s+' -and
$_ -notmatch '^key\s+'
}
# Zertifikate und Schlüssel laden
$caContent = Get-Content $CaFile
$certContent = Get-Content $CertFile
$keyContent = Get-Content $KeyFile
# Neue OVPN-Datei schreiben
$ovpnContent | Set-Content $OutputFile
Add-Content $OutputFile "`n<ca>"
$caContent | Add-Content $OutputFile
Add-Content $OutputFile "</ca>`n<cert>"
$certContent | Add-Content $OutputFile
Add-Content $OutputFile "</cert>`n<key>"
$keyContent | Add-Content $OutputFile
Add-Content $OutputFile "</key>"
Write-Host "Unified .ovpn file generated:"
Write-Host $OutputFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment