Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jmvermeulen/3cf9ffb8a2d578c3e1d58156940600a5 to your computer and use it in GitHub Desktop.
Save jmvermeulen/3cf9ffb8a2d578c3e1d58156940600a5 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment