Use PowerShell to convert your files (exe, ps1, png...) to Base64 and then back from Base64 to the file
In this post I will show you how to convert some files (EXE, PS1, PNG...) to a Base64 code then convert back the file from the Base64.
Context
- You want to download a file on device without to store it somewhere
- You have a script requiring some dependencies like DLL, EXE, PNG...
My use cases
I tested this solution as below:
- Convert ServiceUI.exe to Base64 for displaying toast for user in system context
- Convert some pictures in order to get all in one script
- Convert a PFX certificate to base64 then import it just using the code
Our examples
We will see the below conversion examples:
- Convert an EXE to Base64
- Convert a DLL to Base64
- Convert a TXT file to Base64
- Convert a CSV to Base64
I won't copy all the Base64 code here because it bugs my site :-)
How it works ?
We will proceed as below:
1. Convert the file to Base64
2. On the device we will convert the Base64 to the original file
Convert the file to Base64
See below our different Base64 conversions:
Convert Base64 to original file
See below our different Base64 conversions:
1 commentaire
You have a typo
# Convert from EXE to Base64
$EXE_Path =
$Base64_Code = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes("$ServiceUI_Path"));
It should be $EXE_Path inside the ReadAllBytes
Enregistrer un commentaire