Eintrag von 2026-04-14 10:54:49
# Parameter $ProfileName = 'VPNSCHOOL' # Namespace und Klasse (wie bei der Erstellung) $namespaceName = 'root\cimv2\mdm\dmmap' $className = 'MDM_VPNv2_01' # ProfileName für WMI escapen (Leerzeichen etc. werden zu %20) $ProfileNameEscaped = $ProfileName -replace ' ', '%20' Write-Host "Suche und lösche VPN-Profil: $ProfileName" -ForegroundColor Yellow try { # Hole das passende WMI-Objekt $vpnInstance = Get-CimInstance -Namespace $namespaceName ` -ClassName $className ` -Filter "ParentID='./Vendor/MSFT/VPNv2' AND InstanceID='$ProfileNameEscaped'" if ($vpnInstance) { Remove-CimInstance -CimInstance $vpnInstance -ErrorAction Stop Write-Host "VPN-Profil '$ProfileName' erfolgreich gelöscht." -ForegroundColor Green } else { Write-Host "Kein VPN-Profil mit dem Namen '$ProfileName' gefunden." -ForegroundColor Cyan } } catch { Write-Host "Fehler beim Löschen des Profils: $($_.Exception.Message)" -ForegroundColor Red } # Zusätzlich mit dem normalen VPN-Cmdlet versuchen (für den Fall, dass es auch als normale Verbindung angelegt wurde) try { Remove-VpnConnection -Name $ProfileName -Force -AllUserConnection -ErrorAction SilentlyContinue Write-Host "Normale VPN-Verbindung '$ProfileName' (falls vorhanden) entfernt." -ForegroundColor Green } catch {}
Zurück
Kopieren