I'm always connecting and disconnecting to my VPN and I have a powershell script that connects to the VPN profile and it's brilliant. I dont have to type anything just run it.
However, I always needed to disconnected via the convoluted GUI.
The awesome script I use to connect goes something like:
$vpnName = "MyVPN";
$vpn = Get-VpnConnection -Name $vpnName;
if($vpn.ConnectionStatus -eq "Disconnected"){
rasdial $vpnName;
}
Is there a way to do the opposite?
I cannot seem to find any way of disconnecting via powershell. I cannot use third party software and I can't seem to find anything in PS get-help Vpnconnection that disconnects.
rasdial
has a parameter /DISCONNECT
that should do what you want.
You could rewrite your script to do the disconnect like this:
$vpnName = "MyVPN";
$vpn = Get-VpnConnection -Name $vpnName;
if($vpn.ConnectionStatus -eq "Connected"){
rasdial $vpnName /DISCONNECT;
}
I haven't tested this, but it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With