Skip to content

Paste from PWSH - WT #53

@CrazyWolf13

Description

@CrazyWolf13

Hi

Awesome tool you made!!

I'd like to write a ps1 function that allows me to pipe into wastebin and then get the url-->

cat "Hello World!" | pasteToWaste

I tried this approach, but cannot really get anything to work, have you got an idea?

function pasteToWaste {
    if ($args.Count -eq 0) {
        Write-Error "No file path specified."
        return
    }

    $FilePath = $args[0]

    if (Test-Path $FilePath) {
        $Content = Get-Content $FilePath -Raw
    } else {
        Write-Error "File path does not exist."
        return
    }

    $uri = "http://bin.mydomain.tld"
    try {
        $response = Invoke-RestMethod -Uri $uri -Method Post -Body @{text=$Content} -ErrorAction Stop
        $url = "http://bin.mydomain.tld/$($response.key)"
        Write-Output $url
    } catch {
        Write-Error "Failed to upload the document. Error: $_"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions