PowerShell automation for installing WireGuard on Windows, creating or importing tunnel configurations, and configuring always-on tunnel services with restart-on-failure recovery.
wireguard-setup.ps1 is built for real Windows client deployment work:
- Installs WireGuard from the latest official MSI published at
https://download.wireguard.com/windows-client/ - Supports both interactive operation and batch provisioning through CLI parameters
- Creates new tunnel configs from parameters or script defaults
- Generates a client private key automatically when you do not provide one
- Supports an optional preshared key, either supplied or generated
- Prints the derived client public key in the setup summary
- Optionally exports a server-side peer snippet for easy import on the WireGuard server
- Installs the tunnel as an always-on Windows service
- Configures the tunnel service to restart automatically after failures
- Lists, edits, imports, refreshes, deletes, and removes managed tunnels
- Updates or reinstalls WireGuard cleanly
- Removes the tunnel service, config, WireGuard installation, or everything under the script's managed data directory
The script intentionally does not create or manage a local administrator account. WireGuard tunnel services run under the system service model already, which is the correct direction for an always-on client tunnel.
- Windows PowerShell 5.1 or PowerShell 7+
- Elevated PowerShell session
- Internet access for installing or updating WireGuard from the official download source
The script stores its managed files under:
C:\ProgramData\WinWireGuardSetup\ConfigurationsC:\ProgramData\WinWireGuardSetup\ExportsC:\ProgramData\WinWireGuardSetup\Cache
Config and export files are ACL-restricted to SYSTEM and Administrators.
Run the script without parameters:
.\wireguard-setup.ps1Menu options:
- Install or update WireGuard
- Create or update a tunnel
- Import a tunnel from an existing
.conf - List tunnels and services
- Edit an existing managed tunnel
- Reconfigure an existing tunnel service as always-on
- Delete a tunnel service and/or config
- Remove selected components
- Purge everything
The interactive tunnel workflow will prompt for:
- Tunnel name
- Client address
- Server public key
- Server endpoint
- Allowed IPs
- DNS
- Persistent keepalive
- Whether to generate the private key
- Whether to use and generate a preshared key
- Whether to export a server-side peer snippet
.\wireguard-setup.ps1 -Action InstallWireGuard.\wireguard-setup.ps1 -Action UpdateWireGuardInstall a specific version when it exists on the official MSI page:
.\wireguard-setup.ps1 -Action UpdateWireGuard -WireGuardVersion 0.5.3.\wireguard-setup.ps1 `
-Action SetupTunnel `
-TunnelName office-alwayson `
-ClientAddress 10.77.0.23/32 `
-ServerPublicKey '<server-public-key>' `
-ServerEndpoint vpn.example.com:51820 `
-AllowedIPs '10.0.0.0/8, 192.168.0.0/16' `
-DNS '10.0.0.10, 10.0.0.11' `
-GeneratePrivateKey `
-GeneratePresharedKey `
-ExportServerConfig.\wireguard-setup.ps1 `
-Action SetupTunnel `
-TunnelName branch1 `
-ClientPrivateKey '<client-private-key>' `
-ClientAddress 10.77.0.24/32 `
-ServerPublicKey '<server-public-key>' `
-PresharedKey '<optional-preshared-key>' `
-ServerEndpoint vpn.example.com:51820 `
-AllowedIPs '0.0.0.0/0, ::/0'.\wireguard-setup.ps1 `
-Action ImportTunnel `
-ConfigPath C:\Temp\office.conf `
-TunnelName office-alwayson `
-ConfigureExistingService.\wireguard-setup.ps1 -Action ListTunnelsServices only:
.\wireguard-setup.ps1 -Action ListTunnels -ListServicesOnly.\wireguard-setup.ps1 `
-Action EditTunnel `
-TunnelName office-alwayson `
-OpenEditor `
-ConfigureExistingService.\wireguard-setup.ps1 -Action ConfigureService -TunnelName office-alwayson.\wireguard-setup.ps1 `
-Action DeleteTunnel `
-TunnelName office-alwayson `
-RemoveService `
-RemoveConfigRemove one tunnel service only:
.\wireguard-setup.ps1 -Action Remove -TunnelName office-alwayson -RemoveServiceRemove one config only:
.\wireguard-setup.ps1 -Action Remove -TunnelName office-alwayson -RemoveConfigUninstall WireGuard but keep configs:
.\wireguard-setup.ps1 -Action Remove -RemoveWireGuardPurge everything managed by the script and uninstall WireGuard:
.\wireguard-setup.ps1 -Action Purge-Action Interactive-Action InstallWireGuard-Action UpdateWireGuard-Action SetupTunnel-Action AddTunnel-Action ImportTunnel-Action ListTunnels-Action EditTunnel-Action ConfigureService-Action DeleteTunnel-Action Remove-Action Purge
-TunnelName-ClientPrivateKey-ClientAddress-ServerPublicKey-PresharedKey-ServerEndpoint-AllowedIPs-DNS-PersistentKeepalive
-ConfigPath-ImportConfigText-ExportServerConfig-ServerExportPath
-WireGuardVersion-WireGuardDownloadUrl-SkipWireGuardInstall
-SkipServiceInstall-GeneratePrivateKey-GeneratePresharedKey-ConfigureExistingService-OpenEditor-ListServicesOnly
-RemoveService-RemoveConfig-RemoveWireGuard-PurgeAll
For an always-on client, use:
- narrow
AllowedIPsfor split tunnel 0.0.0.0/0, ::/0only when you explicitly want full tunnelPersistentKeepalive = 25when the client is behind NAT and needs stable inbound reachability
If you omit -ClientPrivateKey, the script generates one locally using wg.exe genkey. The summary prints the derived public key so you can immediately register the peer on the server.
Preshared keys are optional. If you use them, the same value must exist on both ends. The script can either accept -PresharedKey or generate one using -GeneratePresharedKey.
The script configures the WireGuardTunnel$<TunnelName> service with automatic restart-on-failure actions:
- first restart after 5 seconds
- second restart after 15 seconds
- third and later restart after 60 seconds
This is intended for unattended always-on laptop or workstation deployments.
EditTunnel operates on configs managed by this script in C:\ProgramData\WinWireGuardSetup\Configurations. If you already have ad hoc configs elsewhere, import them first so the script can manage the service and lifecycle consistently.
By default the script queries the official WireGuard Windows MSI listing page and selects the latest version for the current architecture. If you need a pinned version or an internal mirror, use -WireGuardVersion and/or -WireGuardDownloadUrl.
- Run
InstallWireGuardor letSetupTunnelinstall it automatically. - Run
SetupTunnelwith generated keys. - Copy the printed public key into the server config, or use the exported peer snippet.
- Verify the
WireGuardTunnel$<TunnelName>service is running.
- Run
ImportTunnel -ConfigPath <path> -TunnelName <name> -ConfigureExistingService - Confirm the service exists with
ListTunnels - Edit and refresh later through
EditTunnel
- Run
DeleteTunnel -TunnelName <name> -RemoveService -RemoveConfig - Recreate it with
SetupTunnelorImportTunnel
- The script expects elevation for all actions.
- It manages plaintext configs under its own secured ProgramData path.
- It does not modify your WireGuard server automatically; it only exports a server-side peer snippet for easier import.
The script's latest-version lookup is based on the official WireGuard Windows installation and MSI listing pages:
https://www.wireguard.com/install/https://download.wireguard.com/windows-client/