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

# Konfigurer en Microsoft VPN med en forhåndsdelt nøgle

Konfigurer en Microsoft L2TP-VPN med en forhåndsdelt nøgle i Remote Desktop Manager ved hjælp af en telefonbogsfil og et PowerShell-forbindelsesscript.

L2TP-konfigurationen af VPN i Remote Desktop Manager krævede en telefonbogsfil. Vi tilføjer også et PowerShell-script i VPN-sessionen for at tilføje VPN'en i Windows og indsætte adgangssætningen. Trinnene er enkle, men kræver præcise oplysninger. I det første trin skal De bruge en telefonbogsfil. Eksemplet gennemgås ikke her, da der findes mange eksempler i Google-søgninger.

1. Opret en telefonbogspost med PBK-filen.
2. Vi konfigurerer en Microsoft VPN-session. Det er vigtigt, at VPN-navnet er den adresse, De vil oprette forbindelse til. PowerShell-scriptet læser ikke oplysningerne i PBK-filen, når den lokale VPN oprettes.

### Konfigurer posten Microsoft VPN som følger

1. Vælg den telefonbog, der blev oprettet tidligere.
2. Klik på opdateringsknappen, og vælg det rigtige VPN-navn på rullelisten.
3. Angiv legitimationsoplysningerne.

Nu er det tid til den forhåndsdelte nøgle. Under ***Fælles – Brugerdefinerede felter*** i ***Brugerdefineret #1*** skal De klikke på navnet og ændre det til PreSharedKey (#1). Angiv derefter den forhåndsdelte nøgle i feltet til højre. Som visuel beskyttelse skal De kun klikke på låsen til sidst (#2).

{% hint style="warning" %}
Den forhåndsdelte nøgle er ikke beskyttet med tilladelsen Vis adgangskode. For at forhindre brugeren i at se den skal De blokere adgangen Rediger til posten. Værdien af et skjult brugerdefineret felt er krypteret og beskyttet med tilladelsen ***Vis følsomme***.
{% endhint %}

Det sidste og vigtigste er integrationen af det PowerShell, der opretter VPN-konfigurationen i Windows.

Under ***Hændelser – Før forbindelse*** skal De vælge ***PowerShell*** og kopiere scriptet ovenfor ind i feltet.

```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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
