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

# Configurar una VPN de Microsoft con una clave precompartida

La configuración de VPN L2TP en Remote Desktop Manager requería un fichero de agenda telefónica (Phonebook). También añadimos un script de PowerShell en la sesión VPN para añadir la VPN en Windows e inyectar la frase de contraseña. Los pasos son sencillos, pero requieren información precisa. En el primer paso, necesitamos un fichero de agenda telefónica. No cubro este ejemplo porque existen demasiados ejemplos de búsqueda en Google.

1. Cree una entrada de agenda telefónica con el fichero PBK.
2. Vamos a configurar una sesión VPN de Microsoft. Importante: el nombre de la VPN debe ser la dirección a la que se va a conectar. El script de PowerShell no lee la información del fichero PBK al crear la VPN local.

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

### Configure la entrada VPN de Microsoft como

1. Seleccione la agenda telefónica creada previamente.
2. Haga clic en el botón de actualizar y seleccione en el desplegable el nombre de VPN correspondiente.
3. Introduzca las credenciales.

Ahora es el momento de la clave precompartida: en ***Common – Custom Fields***, en ***Custom #1***, haga clic en el nombre y cámbielo por PreSharedKey (#1). A continuación, introduzca la clave precompartida en el campo de la derecha. Como protección visual, solo haga clic en el candado del final (#2).

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

{% hint style="warning" %}
La clave precompartida no está protegida con el permiso Ver contraseña. Para evitar que el usuario la vea, debe bloquear el acceso de edición a la entrada. El valor de un campo personalizado oculto está cifrado y protegido con el permiso ***Ver datos sensibles***.
{% endhint %}

El último y más importante es la integración de PowerShell, que creará la configuración de VPN en Windows.

En ***Events – Before Connect***, seleccione ***PowerShell*** y copie el script anterior en el cuadro.

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