Transfer.sh.psm1

function New-Transfersh{

    [CmdletBinding()]

    Param(
        [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
        [String]$Path,
        
        [Int]$MaxDownloads = 0,
        [Int]$MaxDays = 0
    )

    $FileName = Get-ItemPropertyValue -Name name -Path $Path
    $UploadUri = "https://transfer.sh/" + $FileName
    $Headers =  @{}
    if ($MaxDownloads -gt 0) {
        $Headers = $Headers + @{"Max-Downloads" = $MaxDownloads}
        $TimePlural = if ($MaxDownloads -eq 1) {"time"} else {"times"}
        Write-Output "You'll be able to download your file $MaxDownloads $TimePlural using this link."
    }
    if ($MaxDays -gt 0) {
        $Headers = $Headers + @{"Max-Days" = $MaxDays}
        $ExpiryDate =(Get-Date).AddDays($MaxDays)
        $DayPlural = if ($MaxDays -eq 1) {"day"} else {"days"}
        Write-Output "The link will expire in $MaxDays $DayPlural, on $ExpiryDate."
    } else {
        Write-Output "The link will expire in 14 days, on $((Get-Date).AddDays(14))."
    }
    $Response = Invoke-WebRequest -Method Put -Headers $Headers -InFile $Path -Uri $UploadUri
    Write-Host "Link to your file: $Response"
}