Create a new VPN connection via Powershell

2

1

I have to create an application with PowerShell that creates a new VPN connection (adapter) to a given host, with given settings (credentials, etc...).

The computers will be running Windows 7.

I found this cmdlet, but it's only for Windows 8.1 : Add-VpnConnection

Anybody has a PowerShell code to achieve equivalent goal in Windows 7 ?

Many thanks in advance !

Ob1lan

Posted 2014-08-25T12:56:13.990

Reputation: 1 596

Most network-focused cmdlets are Windows 8/8.1 exclusive. If it's possible at all, you'll probably need to reference some .NET Framework classes or WMI objects. – Iszi – 2014-08-25T12:58:46.400

Add-VpnConnection is part of PowerShell 4.0 -- if you'd like PS4 functionality, why not install PowerShell 4 on the Windows 7 machines?

– Ƭᴇcʜιᴇ007 – 2014-08-25T13:16:38.273

@Ƭᴇcʜιᴇ007 thanks for your comment. I indeed considered to install the proper Management Framework, but it would be painfull to do so in my current situation. I'm really looking for a script allowing to achieve the goal in Windows 7, with PowerShell v3. Thanks in advance. – Ob1lan – 2014-08-25T13:24:12.357

@Ƭᴇcʜιᴇ007 As I've stated, most network-focused cmdlets, Add-VpnConnection included, are Windows 8/8.1/2012/2012R2 exclusive. Even with WMF 4.0/PowerShell 4.0 installed, the cmdlets are not available on lower versions of Windows. – Iszi – 2014-08-25T14:51:53.527

1@Ob1lan For future reference, when you're limited to a specific PowerShell version, please specify the PowerShell version in the question body and/or tags. This way, you may avoid getting PS 4.0 answers/comments when you can only go up to 3.0. – Iszi – 2014-08-25T15:23:51.453

Answers

5

Microsoft has a guide on Deploying VPN Connections by Using Windows Powershell and Group Policy. The guide and script are a bit too verbose to fit into the format of a StackExchange answer. (17 page Word document + ~1200 lines of PowerShell + 70 lines of XML)

Depending on how you actually want to deploy the VPN configuration, you may not need the Group Policy portion of the guide. It's simply used to push out the PowerShell script and supporting XML file as part of a logon script.

The PowerShell functionality is summarized in the Solution Overview section:

PowerShell embeds C# code that is run as a part of the script. This article describes a sample PowerShell script that has C# code and calls the RAS API entry points to create and configure VPN connections settings. The input to the PowerShell script is an Extensible Markup Language (XML) file containing the configuration for the VPN connection. As a network administrator, you must customize the XML file for the VPN services in your organization.

Iszi

Posted 2014-08-25T12:56:13.990

Reputation: 11 686

Thanks for your answer, I've already been through this reference, and it seems to be the more pertinent answer to my question. – Ob1lan – 2014-08-25T16:11:07.127

1@Ob1lan If you're having problems with the script, I'd suggest posting over on [so]. PowerShell is kind-of an edge case, since it generally fits here but could be more appropriate for [so] sometimes, but about 90% of the work in that script is being done with C# which definitely belongs on [so]. If you're having problems with the Group Policy part of it, try [sf]. – Iszi – 2014-08-25T17:31:25.020

3I know this answer is ancient, but you wouldn't happen to still have that powershell script would you? It is no longer on the Microsoft download center and can't be found anywhere else. – Grant – 2017-04-06T04:34:41.907