Created
May 8, 2020 08:38
-
-
Save SeidChr/90f050bf48c231e40687dcae9057875b to your computer and use it in GitHub Desktop.
Connecting or disconnecting on a windows-based vpn (rasdial) with notification messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
$vpnName, | |
[ValidateSet("Connect", "Disconnect")] | |
[string] | |
$action | |
) | |
switch ($action) { | |
"Disconnect" { | |
$vpn = Get-VpnConnection -Name $vpnName | |
if ($vpn.ConnectionStatus -eq 'Connected') { | |
rasdial $vpnName /disconnect | |
(New-Object -ComObject Wscript.Shell).Popup('Disconnected from VPN ' + $vpnName + '.', 2, 'Disconnected VPN', 0x0) | |
} else { | |
(New-Object -ComObject Wscript.Shell).Popup('Allready Disconnected from VPN ' + $vpnName + '.', 2, 'Disconnected VPN', 0x0) | |
} | |
} | |
Default { | |
$vpn = Get-VpnConnection -Name $vpnName | |
if ($vpn.ConnectionStatus -eq 'Disconnected') { | |
rasdial $vpnName | |
(New-Object -ComObject Wscript.Shell).Popup('Connected to VPN ' + $vpnName + '.', 2, 'Connected VPN', 0x0) | |
} else { | |
(New-Object -ComObject Wscript.Shell).Popup('Allready Connected to VPN ' + $vpnName + '.', 2, 'Connected VPN', 0x0) | |
} | |
} | |
} | |
# pwshw -command "~\Set-VpnStatus.ps1 -vpnName 'abc' -action 'Connect'" | |
# pwshw -command "~\Set-VpnStatus.ps1 -vpnName 'abc' -action 'Disconnect'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment