ClipboardImage.psm1

function ConvertTo-ImageFormatFromPath([string]$Path)
{
    [CmdletBinding()]

    $x = (Split-Path -Extension -Path $Path) -replace "^[.]",""
    write-debug $x
    switch ($x.ToLower()) {
        "png" { return [System.Drawing.Imaging.ImageFormat]::Png }
        "bmp" { return [System.Drawing.Imaging.ImageFormat]::Bmp }
        "emf" { return [System.Drawing.Imaging.ImageFormat]::Emf }
        "gif" { return [System.Drawing.Imaging.ImageFormat]::Gif }
        "heif" { return [System.Drawing.Imaging.ImageFormat]::Heif }
        "icon" { return [System.Drawing.Imaging.ImageFormat]::Icon }
        "ico" { return [System.Drawing.Imaging.ImageFormat]::Icon }
        "jpeg" { return [System.Drawing.Imaging.ImageFormat]::Jpeg }
        "jpg" { return [System.Drawing.Imaging.ImageFormat]::Jpeg }
        "png" { return [System.Drawing.Imaging.ImageFormat]::Png }
        "tif" { return [System.Drawing.Imaging.ImageFormat]::Tiff }
        "tiff" { return [System.Drawing.Imaging.ImageFormat]::Tiff }
        "webp" { return [System.Drawing.Imaging.ImageFormat]::Webp }
        "wmf" { return [System.Drawing.Imaging.ImageFormat]::Wmf }
        Default {
            return $null
        }
    }
}

Function Save-ClipboardImage()
{
    [CmdletBinding()]
    param(
        [Parameter(Position=0, Mandatory)]
        [string] $Target
    )

    Add-Type -AssemblyName System.Windows.Forms
    $imageFormat = ConvertTo-ImageFormatFromPath -Path $Target
    if ($null -eq $imageFormat) {
        throw "Could not find image format for $Target"
    }

    $image = [System.Windows.Forms.Clipboard]::GetImage()
    $image.Save($Target, $imageFormat)
}

Function Import-ClipboardImage()
{
    [CmdletBinding()]
    param(
        [Parameter(Position=0, Mandatory)]
        [Alias("Path","Source")]
        [string] $ImagePath
    )

    [System.Windows.Forms.Clipboard]::SetImage([System.Drawing.Image]::FromFile($ImagePath))
}