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

# Configurare una VPN Microsoft con una chiave precondivisa

La configurazione VPN L2TP in Remote Desktop Manager richiede un file di rubrica (Phonebook). Aggiungiamo inoltre uno script PowerShell nella sessione VPN per aggiungere la VPN in Windows e iniettare la passphrase. I passaggi sono semplici ma richiedono informazioni precise. Nel primo passaggio, ci serve un file di rubrica. Non tratto questo esempio poiché esistono troppi esempi reperibili con una ricerca su Google.

1. Creare una voce di rubrica con il file PBK.
2. Configureremo una sessione VPN Microsoft. Importante: il nome della VPN deve essere l'indirizzo a cui ci si connetterà. Lo script PowerShell non legge le informazioni contenute nel file PBK durante la creazione della VPN locale.

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

### Configuri la voce VPN Microsoft come

1. Selezioni la rubrica creata in precedenza.
2. Clicchi sul pulsante di aggiornamento e selezioni nel menu a discesa il nome VPN corretto.
3. Inserisca le credenziali.

Ora è il momento della chiave precondivisa: in ***Comune – Campi personalizzati***, nel campo ***Personalizzato #1***, clicchi sul nome e lo modifichi in PreSharedKey (#1). Poi inserisca la chiave precondivisa nel campo a destra. Come protezione visiva, clicchi soltanto sul lucchetto alla fine (#2).

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

{% hint style="warning" %}
La chiave precondivisa non è protetta dall'autorizzazione Visualizza password. Per impedire all'utente di vederla, deve bloccare l'accesso in modifica alla voce. Il valore di un campo personalizzato nascosto è crittografato e protetto dall'autorizzazione ***Visualizza dati sensibili***.
{% endhint %}

L'ultimo e il più importante è l'integrazione dello script PowerShell che creerà la configurazione VPN in Windows.

In ***Eventi – Prima della connessione*** selezioni ***PowerShell*** e copi lo script sopra riportato nella casella.

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