> 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/fr/knowledge-base/troubleshooting-articles/configure-a-microsoft-vpn-with-a-preshared-key.md).

# Configurer un VPN Microsoft avec une clé pré-partagée

La configuration VPN L2TP dans Remote Desktop Manager nécessite un fichier Phonebook. Nous ajoutons également un script PowerShell dans la session VPN pour ajouter le VPN dans Windows et injecter la phrase de passe. Les étapes sont simples, mais requièrent des informations précises. Dans la première étape, nous avons besoin d'un fichier Phonebook. Cet exemple n'est pas couvert ici, car de nombreux exemples sont disponibles sur Google.

1. Créer une entrée dans le fichier PBK.
2. Nous allons configurer une session VPN Microsoft. Important : le nom du VPN doit être l'adresse à laquelle vous vous connecterez. Le script PowerShell ne lit pas les informations du fichier PBK lors de la création du VPN local.

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

### Configurer l'entrée VPN Microsoft

1. Sélectionner le Phonebook créé précédemment.
2. Cliquer sur le bouton d'actualisation et sélectionner dans la liste déroulante le nom de VPN approprié.
3. Saisir les informations d'identification.

Il est maintenant temps de configurer la clé prépartagée. Sous ***Commun – Champs personnalisés***, dans le champ ***Personnalisé n° 1***, cliquer sur le nom et le remplacer par PreSharedKey (n° 1). Saisir ensuite la clé prépartagée dans le champ à droite. À titre de protection visuelle, cliquer uniquement sur le cadenas à la fin (n° 2).

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

{% hint style="warning" %}
La clé prépartagée n'est pas protégée par l'autorisation Afficher le mot de passe. Pour empêcher l'utilisateur de la consulter, vous devez bloquer l'accès en modification de l'entrée. La valeur d'un champ personnalisé masqué est chiffrée et protégée par l'autorisation ***Afficher les données sensibles***.
{% endhint %}

Le dernier élément, et le plus important, est l'intégration du script PowerShell qui crée la configuration VPN dans Windows.

Sous ***Événements – Avant la connexion***, sélectionner ***PowerShell*** et copier le script ci-dessus dans le champ.

```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:

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

The question should be specific, self-contained, and written in natural language.
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.
