Created
October 17, 2021 22:17
-
-
Save BorysVrublevskyi/d25db8ad96c3ad11cd9af49c16808c23 to your computer and use it in GitHub Desktop.
Create SSTP VPN connection on Windows with office options and PassThru option
This file contains 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
$Vpn_Name = Read-Host -Prompt "Input desired VPN Name. Press enter to leave default [MY SSTP]" | |
if ([string]::IsNullOrWhiteSpace($Vpn_Name)) | |
{ | |
$Vpn_Name = "MY SSTP" | |
} | |
Function Add-Country1Routing { | |
# Add-VPNConnectionRoute -ConnectionName $Vpn_Name -DestinationPrefix "192.168.1.0/20" -PassThru | |
# Add-VpnConnectionRoute -ConnectionName $Vpn_Name -DestinationPrefix "192.168.2.22/32" -PassThru | |
# Add-VpnConnectionRoute -ConnectionName $Vpn_Name -DestinationPrefix "192.168.3.0/24" -PassThru | |
} | |
Function Add-Country2Routing { | |
# Add-VPNConnectionRoute -ConnectionName $Vpn_Name -DestinationPrefix "192.168.1.0/20" -PassThru | |
# Add-VpnConnectionRoute -ConnectionName $Vpn_Name -DestinationPrefix "192.168.2.22/32" -PassThru | |
# Add-VpnConnectionRoute -ConnectionName $Vpn_Name -DestinationPrefix "192.168.3.0/24" -PassThru | |
} | |
Function Add-MyVPN { | |
Add-VpnConnection -Name $Vpn_Name -ServerAddress $Server_Address -TunnelType "Sstp" -EncryptionLevel "Required" -AuthenticationMethod MSChapv2 -RememberCredential -SplitTunneling -DnsSuffix "mydomain.loc" -PassThru | |
} | |
$Title = "What is your office location?" | |
$Prompt = "Enter your choice" | |
$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&BIG_Office", "&CoolOffice8)", "&PreatyOffice^^") | |
$Default = 1 | |
$Choice = $host.UI.PromptForChoice($Title, $Prompt, $Choices, $Default) | |
switch($Choice) | |
{ | |
0 { | |
# Office 1 | |
$Server_Address = "office1.mydomain.loc" | |
Add-MyVPN | |
Add-Country1Routing | |
} | |
1 { | |
# Office 2 | |
$Server_Address = "office2.mydomain.loc" | |
Add-MyVPN | |
Add-Country1Routing | |
} | |
2 { | |
# Office 3 | |
$Server_Address = "office3.mydomain.loc" | |
Add-MyVPN | |
Add-Country2Routing | |
} | |
} | |
#pause # use for debug | |
Write-Host "Success! Go to the Internet connections and connect to VPN via $Vpn_Name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment