Public/Get-WinOpenSSL.ps1

<#
    .SYNOPSIS
        This function downloads openssl.exe from either https://indy.fulgan.com/SSL/ or
        http://wiki.overbyte.eu/wiki/index.php/ICS_Download" and adds it to $env:Path
 
    .DESCRIPTION
        See .SYNOPSIS
 
    .PARAMETER OpenSSLWinBinariesUrl
        This parameter is OPTIONAL, however, it has a default value of https://indy.fulgan.com/SSL/
 
        This parameter takes a string that represents the Url that contains a link to a zip file
        containing openssl.exe.
 
    .EXAMPLE
        # Open an elevated PowerShell Session, import the module, and -
 
        PS C:\Users\zeroadmin> Get-WinOpenSSL
         
#>

function Get-WinOpenSSL {
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory=$False)]
        [ValidateSet("https://indy.fulgan.com/SSL/","http://wiki.overbyte.eu/wiki/index.php/ICS_Download")]
        [string]$OpenSSLWinBinariesUrl = "https://indy.fulgan.com/SSL/"
    )

    if ($PSVersionTable.PSEdition -eq "Desktop") {
        [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
    }

    $IWRResult = Invoke-WebRequest -Uri $OpenSSLWinBinariesUrl -UseBasicParsing

    if ($OpenSSLWinBinariesUrl -match "fulgan") {
        $LatestOpenSSLWinBinaryUrl = $OpenSSLWinBinariesUrl + $($IWRResult.Links | Where-Object {$_.OuterHTML -match "win64\.zip"})[-1].href
    }
    if ($OpenSSLWinBinariesUrl -match "overbyte") {
        $LatestOpenSSLWinBinaryUrl = $($IWRResult.Links | Where-Object {$_.OuterHTML -match "win64\.zip"})[0].href
    }
    $OutputFileName = $($LatestOpenSSLWinBinaryUrl -split '/')[-1]
    $OutputFilePath = "$HOME\Downloads\$OutputFileName"

    Invoke-WebRequest -Uri $LatestOpenSSLWinBinaryUrl -OutFile $OutputFilePath

    $ExpansionDirectory = $OutputFilePath -replace '\.zip$',''
    if (Test-Path $ExpansionDirectory) {
        Remove-Item "$ExpansionDirectory\*" -Recurse -Force
    }
    else {
        $null = New-Item -ItemType Directory -Path $ExpansionDirectory
    }
    $null = Expand-Archive -Path $OutputFilePath -DestinationPath $ExpansionDirectory -Force
    $WinOpenSSLFiles = Get-ChildItem -Path $ExpansionDirectory

    $WinOpenSSLParentDir = $WinOpenSSLFiles[0].Directory.FullName
    [System.Collections.Arraylist][array]$CurrentEnvPathArray = $env:Path -split ';' | Where-Object {![System.String]::IsNullOrWhiteSpace($_)}
    if ($CurrentEnvPathArray -notcontains $WinOpenSSLParentDir) {
        $CurrentEnvPathArray.Insert(0,$WinOpenSSLParentDir)
        $env:Path = $CurrentEnvPathArray -join ';'
    }
}