refs #8159 Current user install

This commit is contained in:
Juan Ferrer 2024-10-24 13:16:31 +02:00
parent 337286f773
commit dbe027558c
1 changed files with 19 additions and 9 deletions

View File

@ -1,11 +1,12 @@
# Basic configuration
$vpnName = "Verdnatura"
$vpnHost = "vpn.verdnatura.es"
$vpnSuffix = "verdnatura.es"
param (
$allUsers = $false,
$vpnName = "Verdnatura"
)
# Advanced configuration
$vpnHost = "vpn.verdnatura.es",
$vpnSuffix = "verdnatura.es"
$vpnSplit = $true
$vpnNetworks = @("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16")
$vpnCaUrl = "https://cdn.verdnatura.es/public/verdnatura.der"
@ -16,7 +17,14 @@ $caHash = "028a316a3072f402c10fd7699cb061c93cc5cb15"
$restorePowerShellPolicy = $false
$ErrorActionPreference = "Inquire"
$hasCa = Get-ChildItem Cert:\LocalMachine\Root | Where-Object {$_.Thumbprint -eq $caHash}
if ($allUsers) {
$caPath = "LocalMachine\Root"
} else {
$caPath = "CurrentUser\Root"
}
$caLocation = "Cert:\$caPath"
$hasCa = Get-ChildItem $caLocation | Where-Object {$_.Thumbprint -eq $caHash}
if (!$hasCa) {
Echo "Downloading and installing CA certificate."
@ -28,7 +36,7 @@ if (!$hasCa) {
Import-Certificate `
-FilePath $caFile `
-CertStoreLocation Cert:\LocalMachine\Root `
-CertStoreLocation $caLocation `
| Out-Null
Remove-Item $caFile
@ -39,18 +47,20 @@ Echo "Creating the VPN connection."
Try {
Remove-VpnConnection `
-Name $vpnName `
-AllUserConnection `
-AllUserConnection $allUsers `
-Force `
-ErrorAction Stop
} Catch {
If ($_.Exception.StatusCode -eq 1) {
Throw "Connection '$vpnName' is open, close it before running the script."
} else {
Throw
}
}
Add-VpnConnection `
-Name $vpnName `
-AllUserConnection `
-AllUserConnection $allUsers `
-ServerAddress $vpnHost `
-TunnelType Ikev2 `
-EncryptionLevel Required `