Public/Install-DTXModule.ps1

function Install-DTXModule {
    param(
        [Parameter(Mandatory = $true)]
        [string]$Name,
    
        [Parameter(Mandatory = $true)]
        [string]$Version,
    
        [Parameter(Mandatory = $false)]
        [string]$BucketName = "dtx-software-repo",
    
        [Parameter(Mandatory = $false)]
        [string]$BucketRegion = "eu-west-1",
    
        [Parameter(Mandatory = $false)]
        [string]$ObjectKey = "powershell-modules/$Name/$Version/$Name-v$Version.zip" ,
    
        [switch]$SkipTestImport
    )

    Process {
        $params = @{
            Name         = $Name.ToLower()
            Version      = $Version.ToLower()
            BucketName   = $BucketName.ToLower()
            BucketRegion = $BucketRegion.ToLower()
            ObjectKey    = $ObjectKey.ToLower()
        }

        if ($IsWindows) {
            # Install the module for Windows
            Install-ModuleForWindows @params
        }
        elseif ($IsMacOS -or $IsLinux) {
            # Install the module for non-Windows
            Install-ModuleForNonWindows @params
        }
        else {
            throw "Unsupported operating system."
        }

        if (-not $SkipTestImport) {
            # Test if the module can be imported
            try {
                Write-Host "Testing if module $($Name) can be imported..."
                Import-Module -Name $Name -ErrorAction Stop
                Write-Host "Module $($Name) imported successfully."
            }
            catch {
                throw "Failed to import module $($Name)."
            }
        }
    }
}