## URL for Windows 10 If ( ([System.Environment]::OSVersion.Version).Major -ge 10 ) { $URL = 'https://swupdate.openvpn.org/community/releases/openvpn-install-2.4.7-I607-Win10.exe' } ## URL for Windows 7 ElseIf ( (([System.Environment]::OSVersion.Version).Major -ge 7) -and (([System.Environment]::OSVersion.Version).Major -lt 10) ) { $URL = 'https://swupdate.openvpn.org/community/releases/openvpn-install-2.4.7-I607-Win7.exe' } ## Set the local filename $FILE = '{0}\{1}' -f $Env:TEMP,(Split-Path $URL -Leaf) ## Remove previous package If ( Test-Path $FILE ) { Remove-Item -Path $FILE -Force | Out-Null} ## Download installer Write-Output "Downloading: ${URL}" Try { (New-Object System.Net.WebClient).DownloadFile($URL, $FILE) } Catch { Write-Output $_.Exception.Message } ## Install package Write-Output "Installing: ${FILE}" Try { Start-Process -FilePath $FILE -ArgumentList "/S" -Wait } Catch { $_.Exception.Message } ## Delete installer package If ( Test-Path $FILE ) { Write-Output "Deleting ${FILE}" Try { Remove-Item -Path $FILE -Force } Catch { Write-Output $_.Exception.Message } }