Last active
August 22, 2023 11:42
-
-
Save JohanSelmosson/64c6542ee7bf0efa5ea286d4a9710ef9 to your computer and use it in GitHub Desktop.
Send files through Clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Credit: https://gist.github.com/ethzero/47f657ca635752b5bdb45f99eae40182 | |
function Send-Base64EncodedfileThroughClipboard { | |
[CmdletBinding()] | |
param ( | |
# Path to file to encode | |
[Parameter(Mandatory = $true, | |
Position = 0, | |
ValueFromPipeline = $true, | |
ValueFromPipelineByPropertyName = $true, | |
HelpMessage = "Path to input file. ")] | |
[Alias("PSPath")] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$Path | |
) | |
#$Content = Get-Content -Encoding Byte -Path $path | |
$Content = [System.IO.File]::ReadAllBytes($path) | |
[System.Convert]::ToBase64String($Content) | Set-Clipboard | |
} | |
function Receive-Base64EncodedfileThroughClipboard { | |
[CmdletBinding()] | |
param ( | |
# Output file | |
[Parameter(Mandatory=$true, | |
Position=0, | |
ValueFromPipeline=$true, | |
ValueFromPipelineByPropertyName=$true, | |
HelpMessage="Path to outputfile. ")] | |
[Alias("PSPath")] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$Path | |
) | |
$Base64 = Get-Clipboard -Format Text -TextFormatType Text | |
[System.IO.File]::WriteAllBytes($path, [System.Convert]::FromBase64String($Base64) ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment