How to view my custom VPN service listed in a terminal in order to export it?

Use networksetup or scutil

You can use it to at least establish/ disconnect connections to the VPN.

Use this command to connect the VPN configured with the name "myVPN":

networksetup -connectpppoeservice "myVPN"

Disconnect from the VPN

networksetup -disconnectpppoeservice "myVPN"

When you want to check the connection status

networksetup -showpppoestatus "myVPN"

The "system configuration utility" or scutil command provides access to network configuration, too.

To connect to your VPN use this command:

scutil --nc start "myVPN"

Run the following command to disconnect from the VPN:

scutil --nc stop "myVPN"

If you want to check the connection status, use:

 scutil --nc status "myVPN"

Let's make it even better

Github Code

#!/bin/bash
#
# Provides some basic utilities for VPN connections.

readonly cmd="${1}"
readonly vpn="${2}"


err() {
  echo "$*" >&2
}

validateCmd() {
  if [[ -z "${cmd}" ]]; then 
    err "Command must be provided: [connect, disconnect, status, list]"
    exit 1
  fi
}

validateVpnName() {
  if [[ -z "${vpn}" ]]; then 
    err "VPN name must be provided as second argument"
    exit 1
  fi
}

isConnected() {
  networksetup -showpppoestatus "${vpn}" | grep -qv "^connected$"
}

enterPassword() {
  sleep 1
  osascript -e "tell application \"System Events\" to keystroke \"${1}\""
  osascript -e "tell application \"System Events\" to keystroke return"
}

connect() {
  if ! isConnected; then
    err "Already connected to '${vpn}'"
    exit 1
  fi

  local readonly password="$(security find-generic-password -s "${vpn}" -w)"
  if [[ -z "${password}" ]]; then
    err "Unable to find VPN password in keychain"
    exit 1
  fi

  scutil --nc start "${vpn}"
  enterPassword "${password}"
}

disconnect() {
  scutil --nc stop "${vpn}"
}

status() {
  scutil --nc status "${vpn}"
}

list() {
  scutil --nc list
}

main() {
  validateCmd

  case "${cmd}" in
    connect)
      validateVpnName
      connect "${vpn}"
      ;;
    disconnect)
      validateVpnName
      disconnect "${vpn}"
      ;;
    status)
      validateVpnName
      status "${vpn}"
      ;;
    list)
      list
      ;;
    *)
      err "Unexpected cmd '${cmd}', must be one of [connect, disconnect, status, list]"
      exit 1
      ;;
  esac
}

set -e 
main "${@}"
set +e

Open the script in an editor and add this code. Let's say it's called vpnConnection. Add #!/bin/bash so that it can start without further ado

echo `'#!/bin/bash'` > ~/vpnConnection.sh && chmod +x ~/vpnConnection.sh

./vpnConnection.sh list show all VPN connections

./vpnConnection.sh connect "myVPN" Connect to the VPN "myVPN" and automatically enter the password

./vpnConnection.sh disconnect "myVPN" disconnect the VPN "myVPN"

./vpnConnection.sh status "myVPN" view the connection status for VPN "myVPN"