Last active
August 22, 2023 11:45
-
-
Save ethzero/47f657ca635752b5bdb45f99eae40182 to your computer and use it in GitHub Desktop.
Transferring binary content by way of clipboard via Powershell
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
## 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
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