There are times that you need to include files with a PowerShell script but maybe you don't necessarily want to have several separate files.
There are times that you need to include files with a PowerShell script but maybe you don’t necessarily want to have several separate files. We can easily convert those files to base64 then embed them into a PowerShell script where it can easily be decoded as needed.
For example, lets say we have a file called “required.dll” First you would convert the file to base64, to save space lets also compress the base64, and to save time lets add it to our clipboard so we can paste it into our script.
Get-Content require.dll -Raw -Encoding Byte | ConvertTo-DeflateBase64String | Set-Clipboard
Now you paste the contents of your clipboard to where you want in your script, for example:
$dll = "paste-here"
You can then either deflate directly in your script:
$requireddll = ConvertFrom-DeflateBase64String $dll
Or deflate and save back to a file:
ConvertFrom-DeflateBase64String $dll -OutputFormat Byte | Set-Content required.dll -Encoding Byte -NoNewLine
By using the -Encoding parameter this should work with any file type.