PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,466 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi all ) please need a help, I have a scipt to disconnect VPN (powershell):
$vpnName = "MyVPN";
$vpn = Get-VpnConnection -Name $vpnName;
if($vpn.ConnectionStatus -eq "Connected"){
rasdial $vpnName /DISCONNECT;
}
Please tell me, how I can find and set var $vpnName if I know just part of VPN name, like "vash", full VPN name maybe VPNvashinsider or VPN vashinsider or vpnvashinsider.com
I need regex how I can set var $vpnName taked from part of word "vash"? Thanks a lot!
Something like this might work for you:
$vpnName = "MyVPN";
[array]$vpns = Get-VpnConnection |
Where-Object {$_.Name -Like "*$vpnName" -AND $_.ConnectionStatus -eq "Connected"}
if ($vpns.count -eq 1){
rasdial $vpnName /DISCONNECT
}
else{
Write-Host "Multiple, or no, ($($vpns.count)) VPN connections match '$vpnName'"
$vpns.Name
}