> 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écessitait un fichier d'annuaire téléphonique. 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 nécessitent des informations précises. À la première étape, nous avons besoin d'un fichier d'annuaire téléphonique. Je ne couvre pas cet exemple, car il existe trop d'exemples de recherche Google.

1. Créez une entrée d'annuaire téléphonique avec 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>

### Configurez l'entrée VPN Microsoft comme suit

1. Sélectionnez l'annuaire téléphonique créé précédemment.
2. Cliquez sur le bouton d'actualisation et sélectionnez dans la liste déroulante le nom de VPN approprié.
3. Saisissez les identifiants.

Il est maintenant temps de s'occuper de la clé prépartagée. Sous ***Commun – Champs personnalisés***, dans ***Personnalisé #1***, cliquez sur le nom et remplacez-le par PreSharedKey (#1). Saisissez ensuite la clé prépartagée dans le champ à droite. Comme protection visuelle, cliquez seulement sur le cadenas à la fin (#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 la permission Voir le mot de passe. Pour empêcher l'utilisateur de la voir, vous devez bloquer l'accès Modifier à l'entrée. La valeur d'un champ personnalisé masqué est chiffrée et protégée par la permission ***Voir les données sensibles***.
{% endhint %}

La dernière étape et la plus importante est l'intégration du PowerShell qui créera la configuration VPN dans Windows.

Sous ***Événements – Avant la connexion***, sélectionnez ***PowerShell*** et copiez le script ci-dessus dans la boîte.

```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/fr/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.
