Hi,
Have you ever been asked:
How to run the script in a secure way without exposing the code?

I think everyone has been asked about that.
That is why this post might help you somehow.
Under my GitHub repo you can find 2 useful scripts:
https://github.com/przybylskirobert/ADSecurity/tree/master/Script_encryption

  • Encrypt-Script.ps1 – that’s obvious this script will encrypt our script.
  • Execute-Script.ps1 – this script will execute our encrypted script.

Let’s work with a simple script that will save ipconfig to file

$path = test-path -path C:\test
if ($path -eq $false){
    new-item -ItemType Directory -Path C:\ -Name Test -Force
}
ipconfig >> c:\test\config.log

Encrypt Time!

Save it as a c:\test\script.ps1

Now let’s copy Encrypt-Script.ps1 to the c:\test directory and run the following code

.\Encrypt-Script.ps1 -Path "C:\test" -ScriptName 'script.ps1' -Credential (Get-credential)

We will encrypt our Script.ps1 file with the credentials

Script Encryption
Script Encrypted

Execute Time!

So let’s now move our Execute-Script.ps1 and script.bin files to other machine and run

.\Execute-Script.ps1 -$BinFilePath"C:\test\script.bin" -Credential (Get-credential)
Script execution
Script executed

As you can see there is an easy way to encrypt your file.

Comments are closed.