-
Notifications
You must be signed in to change notification settings - Fork 0
/
ovpn_setup.ps1
67 lines (52 loc) · 2.03 KB
/
ovpn_setup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<#
.DESCRIPTION
Configure OpenVPN client by performing the following tasks:
- Load configuration parameters from config.json
- If OpenVPN client is not installed, install it
- If OpenVPN client and version is obsolete, update it
- Download the OpenVPN configuration file using user credentials
- Configure the OpenVPN with the downloaded configuration file
- Configure the OpenVPN service to start automatically
- Start the OpenVPN service
- Test the OpenVPN connection
.PARAMETER config.json
Parameters are loaded from config.json file include:
- OpenVPN URL
- Configuration file URL
- Remote Desktop firewall rule name
- Verbosity level
- Log file path
.EXAMPLE
.\ovpn_setup.ps1
.NOTES
E! SFI Anatel, 2024
#>
$DEFAULT_CONFIG_FILE = "config.json"
# Check if the configuration file exists
if (-not (Test-Path $DEFAULT_CONFIG_FILE)) {
Write-Error "Configuration file not found: $DEFAULT_CONFIG_FILE"
exit 1
}
# Read the content of the JSON configuration file
$config = Get-Content -Raw -Path $DEFAULT_CONFIG_FILE | ConvertFrom-Json
# check if OpenVPN client is installed
if (-not (Get-Command -Name "openvpn" -ErrorAction SilentlyContinue)) {
Write-Host "OpenVPN client not found. Installing OpenVPN client..."
# Install OpenVPN client
choco install openvpn -y
}
# Install SharePointPnPPowerShellOnline module if not already installed
# Keys and instalation files are stored in sharepoint folders
if (-not (Get-Module -Name SharePointPnPPowerShellOnline -ErrorAction SilentlyContinue)) {
Install-Module -Name SharePointPnPPowerShellOnline -Force -AllowClobber
}
# Connect to SharePoint with MFA authentication
Connect-PnPOnline -Url "<SharePoint Site URL>" -UseWebLogin
# Define the SharePoint file URL
$sourceUrl = "<SharePoint File URL>"
# Define the local file path to save the downloaded file
$destinationPath = "<Local File Path>"
# Download the file from SharePoint
Get-PnPFile -Url $sourceUrl -Path $destinationPath
# Disconnect from SharePoint
Disconnect-PnPOnline