Windows VPN store PSK - Powershell script does not work. Still the best option ?

Implemented

Windows VPN store PSK - Powershell script does not work. Still the best option ?

avatar

Hello

For a long time we've been using an embedded phonebook document to store details about our customers Windows VPN connections. This works mostly well, however it is a pain in the *** that we have to specify the PSK manually every time we connect from a new PC.

I found this topic, explaining how a Powershell script can be used to create the tunnels ad hoc and embed the PSK automatically, that would be a long step ahead from where this implementation is now. https://forum.devolutions.net/topics/33404/store-microsoft-vpn-configuration-profile-in-rdm

My current problem is that as soon as launching the VPN it (the PS script) states that the VPN-connection already exists which it doesn't. I don't know if the script reads the "$RDM.Connection.VPN.Name" wrong or what happens. If I run the script manually outside RDM I can create a VPN with the same name just fine...

I am trying to use the "Default Phonebook" (in Windows) to not have a centrally stored phonebook document, we have had this in the past, but it hasn't been very reliable.

I have attached screenshots of my configuration.

I'm using RDM V.2020.3.18.0

It might be that there is a better way of creating a Windows VPN and storing the PSK with it automatically, if so, please let me know.

All Comments (48)

avatar

Hello Joe,

At the moment, the PowerShell script provided here:https://forum.devolutions.net/topics/33404/store-microsoft-vpn-configuration-profile-in-rdm#138180

is indeed the best solution we have.

According to your screenshots, you have selected "Default Phonebook" in the properties of your VPN entry. Could you please select "Phonebook document" instead as shown in the link I have provided you above? I suspect that in doing so, you will not receive this message anymore:

That being said, a feature request has already been opened with our Engineering Department in order to see if that is something that we could add in RDM. For further reference, the ticket number is RDMW-4275.

Best regards,

James Lafleur

avatar

Hello James

Just tried to use a phonebook document instead, this fails in the same way...

Anyway I would like to stick to Windows default phonebook as we sometimes has problems closing the Windows VPN from RDM because RDM can't access the phonebook document as it is residing on a network drive which isn't always reachable because our Windows VPNs does not support split-tunneling hence no connection to the drive when on VPN session through RDM.

avatar

Hello Joe,

At the moment, I am looking on our end in order to see if we have a test environment that I could use to try this out. Since you confirm that the same script works outside of RDM, it should work in RDM as well.

That being said, after creating the file manually outside of RDM using the script, could you please try to launch it through RDM once more and see if the VPN works? Please note that RDM need to be ran as an administrator in order for the VPN to be launched properly.

Best regards,

James Lafleur

avatar

Hi James

Looking forward to hear how it goes with the testing in your end. If you need a Windows VPN to connect to, I can supply you credentials to one in our test-environment.

I just tried to add the following "Before Open"-event to the VPN-entry in RDM: "Add-VpnConnection -RememberCredential -Name test -ServerAddress 1.2.3.4 -TunnelType L2tp -L2tpPsk wegaweg -AuthenticationMethod Pap -Force -ErrorAction SilentlyContinue;" This does successfully create the VPN-adapter on my PC.

The problem is definitely that when running the supplied script in the "Before open"-event it detects the adapter the wrong way, thinking it is already created on the PC even though it's not, and that leads it to not creating the adapter at all.

Best regards

Joe

avatar

Hello Joe,

Would it be possible for you to replace the scripts your are currently using with the one below instead and see if this issue still occurs?

$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)}; }

Best regards,

James Lafleur

avatar

Hello James

Just replaced the script with the new one. This time the VPN is indeed created if not present.

When opening the VPN-session from RDM it doesn't launch the VPN, either after creating it nor concluded it's already there.

Do I have to enter additional information anywhere in order for it to actually start the VPN ?

My exact configuration looks like my screenshots posted earlier. The only change is your updated PS script.

Best regards

Joe

avatar

Hello Joe,

After going back through our exchanges, I noticed that I did not have a confirmation from you that RDM was run as an administrator. Is it your case? If not, could you please try to do so and see if the VPN is started properly?

Best regards,

James Lafleur

avatar

It is running as admin, still doesn't work.

It opens just fine on your existing Windows VPNs, but those are configured on the parent folder of the entries where we would utilize the VPN. I can't find a option there to add the "Before Open"-Event.

This new VPN entry I'm currently playing with is added under the parent folder as a VPN entry, because I see that I can add the "Before Open"-Event here just as Jeff D's guide on the topic indicates. As stated, the script creates the VPN but it's not launched.

I would prefer to be able to add the "Before Open"-Event on the parent folder, but it doesn't seem like an option to me.

avatar

Sorry. Works now. Forgot to change the phonebook back to "embedded" after playing with using our existing document.

avatar

Tried to use the following at the "After close"-event to automatically delete the VPN after ended session. It doesn't delete the VPN. Do you have an idea on that too?

Remove-VpnConnection -Name $RDM.Connection.VPN.Name; -Force

Edit: Deleted the semicolon after the variable name, works now.

avatar

Hello Joe,

Great! I am glad to see that you have been able to solve this issue!

Do not hesitate to contact us again fi you require further assistance.

Best regards,

James Lafleur

avatar

Thank you. I am glad to always receive good help from you guys at this forum.

Merry Christmas

Best regards

Joe