Question:
I have a PowerShell script which installs a patch (contains set of files to be added) on a customer machine. For this, I have created a batch file which executes this PowerShell script.
For the customer to run this batch file, the PowerShell script file must be placed onto the customer machine as well.
The PowerShell script is in text format, which can be read and understood by the customer easily.
Can we convert this script file into some non-readable format (e.g. bin or exe), so that it is not readable by the customer?
Answer:
You can convert the script to Base64 encoding, so that it’s not immediately readable. To convert a PowerShell script file to a Base64 String, run the following command:
1 2 |
$Base64 = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes('c:\path\to\script file.ps1')); |
To launch the Base64-encoded script, you can call PowerShell.exe as follows:
1 2 |
powershell.exe -EncodedCommand |
For example, the following command:
1 2 |
powershell.exe -EncodedCommand VwByAGkAdABlAC0ASABvAHMAdAAgAC0ATwBiAGoAZQBjAHQAIAAiAEgAZQBsAGwAbwAsACAAdwBvAHIAbABkACEAIgA7AA== |
Will return the following results:
1 2 |
Hello, world! |