Skip to content

Instantly share code, notes, and snippets.

@SeidChr
Created May 8, 2020 08:38
Show Gist options
  • Save SeidChr/90f050bf48c231e40687dcae9057875b to your computer and use it in GitHub Desktop.
Save SeidChr/90f050bf48c231e40687dcae9057875b to your computer and use it in GitHub Desktop.
Connecting or disconnecting on a windows-based vpn (rasdial) with notification messages
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