Win 10 auto-vpn

How to make win 10 auto-vpn, with eap configurations file, adding and removing script. plseasd help!

On Windows 10 you can use add-vpnconnection - https://docs.microsoft.com/en-us/powershell/module/vpnclient/add-vpnconnection?view=win10-ps

and remove-vpnconnection - https://docs.microsoft.com/en-us/powershell/module/vpnclient/remove-vpnconnection?view=win10-ps

add-vpnconnection can read xml configuration files.

I tried with above method, but add-vpnconnection does not seem to recognize or find object which is VPN connections which is already added.

If I create new VPN Connections, how do I modify scripts to make it work on all machines and not just my machine.

Please advise?

You can use Get-VPNConnection to check whether VPN connection under certain already exists or list them all. If it doesnt, use Add-VPNConnection to create it through the xml file, if it does you can either remove it and re-add it or use Set-VPNConnection to modify it. You can create a toolkit package for it a send it through SCCM/Intune to all your machines.

I’m not sure what’s unclear.

here is omitted script which I am trying to run and getting obj not found error:

$Script = ‘$ProfileName = ‘’’ + $ProfileName + ‘’’’
$ProfileNameEscaped = $ProfileName -replace ’ ', ‘%20’

$session = New-CimSession

try
{
$deleteInstances = $session.EnumerateInstances($namespaceName, $className, $options)
foreach ($deleteInstance in $deleteInstances)
{
$InstanceId = $deleteInstance.InstanceID
if ("$InstanceId" -eq “$ProfileNameEscaped”)
{
$session.DeleteInstance($namespaceName, $deleteInstance, $options)
$Message = “Removed $ProfileName profile $InstanceId”
Write-Host “$Message”
} else {
$Message = “Ignoring existing VPN profile $InstanceId”
Write-Host “$Message”
}
}
}
catch [Exception]
{
$Message = “Unable to remove existing outdated instance(s) of ProfileName profile: _”
Write-Host “$Message”
exit
}

##Set-VpnConnection -Name $ProfileName -SplitTunneling $True

$Connection = Get-VpnConnection -Name $ProfileName
write-host $Connection

if($Connection)
{
$Message = “Unable to get ProfileName connection profile: _”
Write-Host “$Message”
exit
}
$EAPSettings= $Connection.EapConfigXmlStream.InnerXml

Get-VpnConnection : VPN connection “NAME OF VPN CONNECTION” was not found. : The system could not find the phone book entry for this connection.
At “Location”.ps1:40 char:15

  • $Connection = Get-VpnConnection -Name $ProfileName
  •           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (“NAME OF VPN CONNECTION”:root/Microsoft/…S_VpnConnection) [Get-VpnConnection], CimException
    • FullyQualifiedErrorId : VPN 623,Get-VpnConnection

BUT When I check auto-vpn profile… “NAME OF VPN CONNECTION” is already there…

If you want to add/get global vpn connections so they are available to all users not just the current one then you need the -AllUserConnection parameter.

So

$Connection = Get-VpnConnection -Name $ProfileName -AllUserConnection

what I want to do is create vpn profile with EAP, User certificate, all settings in xml file.
And then import it to created VPN profile.

What I am getting stuck at is if VPN profile is created with user certificate and EAP settings. I am unable to import my xml file to exisiting VPN profile.

SO, What I have so far is :

$A=New-EapConfiguration -TLS -UserCertificate
##Add-VpnConnection -Name “VPN” -ServerAddress “serveraddr” -TunnelType Ikev2 -EncryptionLevel Required -AuthenticationMethod Eap -SplitTunneling -RememberCredential -EapConfigXmlStream $A.EapConfigXmlStream -PassThru

adds vpn profile with eap and option for user certificate#####

$######## Getting stuck on this part to serialize and import xml settings to above created VPN connection###############################

$B = [xml](Get-Content -Path “VPN_Profile.xml”) or Import-Clixml -Path “VPN_Profile.xml”
$B
Set-VpnConnection -Name “VPN” -ServerAddress “serveraddr” -TunnelType Ikev2 -EncryptionLevel Required -AuthenticationMethod Eap -SplitTunneling -RememberCredential -EapConfigXmlStream $B.EapConfigXmlStream -PassThru

Well then your xml file isnt in a form that the command expects.

This could help you create one: https://docs.microsoft.com/en-us/windows/client-management/mdm/eap-configuration