> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/rdm/de/knowledge-base/troubleshooting-articles/configure-a-microsoft-vpn-with-a-preshared-key.md).

# Ein Microsoft VPN mit einem vorinstallierten Schlüssel konfigurieren

Die VPN-L2TP-Konfiguration in Remote Desktop Manager erforderte eine Telefonbuchdatei. Wir fügen außerdem ein PowerShell-Skript in die VPN-Sitzung ein, um das VPN in Windows hinzuzufügen und die Passphrase einzufügen. Die Schritte sind einfach, erfordern jedoch präzise Informationen. Im ersten Schritt benötigen wir eine Telefonbuchdatei. Ich behandle dieses Beispiel nicht, da bereits zu viele Google-Suchbeispiele existieren.

1. Erstellen Sie einen Telefonbucheintrag mit der PBK-Datei.
2. Wir werden eine Microsoft VPN-Sitzung konfigurieren. Wichtig: Der VPN-Name muss die Adresse sein, mit der Sie sich verbinden werden. Das PowerShell-Skript liest die Informationen in der PBK-Datei nicht, wenn das lokale VPN erstellt wird.

   <figure><img src="https://cdnweb.devolutions.net/docs/docs_en_kb_KB4243.png" alt=""><figcaption></figcaption></figure>

### Konfigurieren Sie den Microsoft VPN-Eintrag wie folgt

1. Wählen Sie das zuvor erstellte Telefonbuch aus.
2. Klicken Sie auf die Aktualisieren-Schaltfläche und wählen Sie im Dropdown-Menü den richtigen VPN-Namen aus.
3. Geben Sie die Anmeldeinformationen ein.

Nun ist es Zeit für den Preshared Key: Klicken Sie unter ***Common – Custom Fields*** im Feld ***Custom #1*** auf den Namen und ändern Sie ihn zu PreSharedKey (#1). Geben Sie dann den Preshared-Key in das Feld auf der rechten Seite ein. Als visuellen Schutz klicken Sie nur auf das Schloss am Ende (#2).

<figure><img src="https://cdnweb.devolutions.net/docs/docs_en_kb_KB4244.png" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Der Preshared Key ist nicht mit der Berechtigung „Passwort anzeigen“ geschützt. Um zu verhindern, dass der Benutzer ihn sieht, müssen Sie den Bearbeitungszugriff auf den Eintrag blockieren. Der Wert eines versteckten benutzerdefinierten Feldes ist verschlüsselt und mit der Berechtigung ***View sensitive*** geschützt.
{% endhint %}

Der letzte und wichtigste Punkt ist die Integration des PowerShell-Skripts, welches die VPN-Konfiguration in Windows erstellt.

Wählen Sie unter ***Events – Before Connect*** die Option ***PowerShell*** und kopieren Sie das obige Skript in das Feld.

```powershell
# Run from elevated PowerShell session (-verb RunAs)
# May need to run commented line below and answer 'A' OR 'Y'
#set-executionpolicy -executionpolicy unrestricted

$wshell = New-Object -ComObject Wscript.Shell;
$ServerAddress = $RDM.Connection.VPN.Name;
$ConnectionName = $RDM.Connection.VPN.Name;
$PresharedKey = $RDM.Connection.MetaInformation.CustomField1Value;

$Exists = Get-VpnConnection -Name $ConnectionName -ErrorAction SilentlyContinue -ErrorVariable ProcessError;
If ($ProcessError) {$wshell.Popup('RDM is creating the VPN  ' + $ConnectionName,0,'Creation',0x0);
$Exists = $False};

If ($Exists -eq $False){;
$ServerAddress = $ServerAddress;
$PresharedKey = $PresharedKey;

Add-VpnConnection -RememberCredential -Name $ConnectionName -ServerAddress $ServerAddress -TunnelType L2tp -L2tpPsk $PresharedKey -AuthenticationMethod Pap -Force -ErrorAction SilentlyContinue;
$ExistsTest = Get-VpnConnection -Name $ConnectionName -ErrorAction SilentlyContinue -ErrorVariable ProcessError;
If ($ProcessError) { $wshell.Popup('VPN ' + $ConnectionName + ' - Cannot be created' + $Error,0,'Error',0x0)} else {$wshell.Popup('VPN ' + $ConnectionName + ' - Succefully Created ',0,'Success',0x0)};
} else {$wshell.Popup('VPN ' + $ConnectionName + ' - Already Exists',0,'Done',0x0)};
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/rdm/de/knowledge-base/troubleshooting-articles/configure-a-microsoft-vpn-with-a-preshared-key.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
