Skip to content

Instantly share code, notes, and snippets.

@ethzero
Last active August 22, 2023 11:45
Show Gist options
  • Save ethzero/47f657ca635752b5bdb45f99eae40182 to your computer and use it in GitHub Desktop.
Save ethzero/47f657ca635752b5bdb45f99eae40182 to your computer and use it in GitHub Desktop.
Transferring binary content by way of clipboard via Powershell
## Powershell method of transfering small (< 1 MB) binary files via Clipboard
##
## NB: Unwise to attempt to encode binary files exceeding 1 MB due to excessive memory consumption
## Powershell 5.0>
# On the transmission end:
$Content = Get-Content -Encoding Byte -Path binaryfile.xxx
[System.Convert]::ToBase64String($Content) | Set-Clipboard
# On the receiving end
$Base64 = Get-Clipboard -Format Text -TextFormatType Text
Set-Content -Value $([System.Convert]::FromBase64String($Base64)) -Encoding Byte -Path binaryfile.zip
## Prior to Powershell 5.0
# On the transmission end:
$Content = Get-Content -Encoding Byte -Path binaryfile.xxx
[System.Convert]::ToBase64String($Content) | clip
# On the receiving end:
# Paste the Base64 encoded contents in a text file manually:
$Base64 = Get-Content –Path binaryfile.xxx.base64_encoded.txt
Set-Content -Value $([System.Convert]::FromBase64String($Base64)) -Encoding Byte -Path binaryfile.zip
@JohanSelmosson
Copy link

I created a powershell function of the above and i incorporated the suggestion from @fred-gagnon. Very useful, big thanks to both of you.

https://gist.github.com/JohanSelmosson/64c6542ee7bf0efa5ea286d4a9710ef9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment