I am creating a VPN in Powershell.
I want to get information on this VPN with -AllEuserConnection
,but when trying to displaying by -Name
I get an error. I tried many variations of the name but with no success. I need to access by name to do another command on the VPN.
Here is the example of the error I am getting:
PS C:\WINDOWS\system32> Add-VpnConnection -Name "USERVPN" -ServerAddress "123.456.789.123" -TunnelType L2tp -AuthenticationMethod Pap -EncryptionLevel Optional -L2tpPsk "UserKey" -Force -AllUserConnection
WARNING: The currently selected encryption level requires EAP or MS-CHAPv2 logon security methods. Data encryption will
not occur for Pap or Chap.
PS C:\WINDOWS\system32> Get-VpnConnection -AllUserConnection
Name : USERVPN
ServerAddress : 123.456.789.123
AllUserConnection : True
Guid : {8119DEDB-B9C1-4660-B3EA-5F14B0B2205D}
TunnelType : L2tp
AuthenticationMethod : {Pap}
EncryptionLevel : Optional
L2tpIPsecAuth : Psk
UseWinlogonCredential : False
EapConfigXmlStream :
ConnectionStatus : Disconnected
RememberCredential : False
SplitTunneling : False
DnsSuffix :
IdleDisconnectSeconds : 0
PS C:\WINDOWS\system32> Get-VpnConnection -Name "USERVPN"
Get-VpnConnection : VPN connection USERVPN was not found. : The system could not find the phone book entry for this
connection.
At line:1 char:1
+ Get-VpnConnection -Name "USERVPN"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (USERVPN:root/Microsoft/...S_VpnConnection) [Get-VpnConnection], CimExce
ption
+ FullyQualifiedErrorId : VPN 623,Get-VpnConnection
On the Add-VpnConnection
Cmdlet you're using the switch parameter -AllUserConnection
, so you need to call it on the Get-VpnConnection
also.
Add-VpnConnection -Name "USERVPN" -ServerAddress "123.456.789.123" -TunnelType L2tp -AuthenticationMethod Pap -EncryptionLevel Optional -L2tpPsk "UserKey" -Force -AllUserConnection
Get-VpnConnection -Name USERVPN -AllUserConnection
You also need to call it on other Cmdlets, like Remove-VpnConnection
.
Tested here: