What It Does
Run it as SYSTEM from your RMM with Client set to the VPN this PC uses. It acts only when something is wrong: a client service that is not running, a built-in VPN profile whose server name does not resolve, or Force=true. Otherwise it says the client is already healthy and changes nothing.
A stopped service is started and checked until it is running. With Force=true a running service is restarted too, which drops a connected tunnel and its user's session, so the script warns when someone is signed in. It then flushes the DNS client cache and re-registers the PC in DNS. For the built-in Windows VPN there is no service, so the repair is the DNS step and a check that the profile's server name now resolves.
A disabled service is reported and left disabled. If there is no other repair to do and Force is off, the run ends in error. Otherwise it proceeds with the other repairs. When a named WireGuard tunnel is missing, it errors if other tunnels exist and skips if there are none. A dry run lists what it would do.
Partly tested: the built-in Windows VPN and WireGuard were tested on Windows 11 with a real tunnel service stopped, restarted and disabled. FortiClient, Cisco Secure Client and GlobalProtect were tested only on a PC without them.
Before You Run It
- Run test-vpn-client first, and set Client to the VPN this PC uses.
- Use Force only when the client is running but stuck, and warn the user first: it drops their VPN session.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: Low. Set DryRun=true, or run it with -WhatIf, to list every change without making any.
- What it changes: Starts (or with Force restarts) the VPN client service; flushes the DNS client cache; re-registers DNS.
- Restart: It never restarts the machine.
- Typical run: Under 1 minute.
- Example answer: "Started service PanGPS; DNS cache flushed and re-registered"
- Partly tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases; some of the products it supports were not available to test. The help says which.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- Client: BuiltIn (default), FortiClient, CiscoSecureClient, GlobalProtect or WireGuard.
- ProfileName: BuiltIn: act only for this profile name. WireGuard: only this tunnel name. Empty (default) means all. Ignored for the other clients.
- Force: true to restart a service that is already Running, and to flush DNS even when everything looks healthy. Can disconnect a user's VPN. Default false.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.