$NewVPN = "XXXXVPN"
$HasNew = Get-VpnConnection -AllUserConnection $NewVPN -ErrorAction SilentlyContinue
#Check VPN Exists
if (-not $HasNew) {
Write-Output "VPN Not Found"
Exit 1
}
#Check Routes
$Routes = (Get-VpnConnection -Name $NewVPN -AllUserConnection).Routes.DestinationPrefix
if ($Routes -contains "10.5.0.0/16") { } else {
Write-Output "US AZ Route Not Found"
Exit 1
}
#Hide Filenames
$RegPath = "HKLM:\SYSTEM\CurrentControlSet\Services\RasMan\PPP"
$Name = "MaxConfigure"
$value = "60"
#Registry Detection Template
If (!(Test-Path $RegPath))
{
write-output 'Registry needed fixing '
Exit 1
}
$check=(Get-ItemProperty -path $RegPath -name $Name -ErrorAction SilentlyContinue).$Name
if ($check -ne $value){
write-output 'Registry needed fixing '
Exit 1
}
Exit 0
$OldVPN = "XXXXX"
$NewVPN = "XXXXX"
$HasNew = Get-VpnConnection -AllUserConnection $NewVPN -ErrorAction SilentlyContinue
$HasOld = Get-VpnConnection -AllUserConnection $OldVPN -ErrorAction SilentlyContinue
$RegPath = "HKLM:\SYSTEM\CurrentControlSet\Services\RasMan\PPP"
$Name = "MaxConfigure"
$value = "60"
if ($HasOld) {Remove-VpnConnection -Name $OldVPN -AllUserConnection -Force -PassThru}
if (-not $HasNew) {
Add-VpnConnection -Name $NewVPN `
-ServerAddress "XXXXX" `
-TunnelType "sstp" `
-EncryptionLevel "Required" `
-DnsSuffix "XXXXX" `
-AuthenticationMethod MSChapv2 `
-UseWinlogonCredential `
-AllUserConnection `
-RememberCredential `
-PassThru `
-SplitTunneling
}
Add-VpnConnectionRoute -ConnectionName $NewVPN -DestinationPrefix 10.5.0.0/16
Add-VpnConnectionRoute -ConnectionName $NewVPN -DestinationPrefix 10.7.0.0/16
New-ItemProperty -Path $RegPath -Name $name -Value $value -PropertyType DWORD -Force | Out-Null