Use PowerShell to convert your files (exe, ps1, png...) to Base64 and then back from Base64 to the file

1 A+ A-

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.


- 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:

PowerShell Base64 578148967296107764

Enregistrer un commentaire

1 commentaire

Unknown a dit…

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

Accueil item



Learn KQL in one month

You want to support me ?

Mes articles en français

Books in French