Convert PowerShell script into non-readable format

后端 未结 3 1522
时光说笑
时光说笑 2020-12-30 16:36

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 PowerS

3条回答
  •  甜味超标
    2020-12-30 17:11

    I tried the solution proposed by @TrevorSullivan, but it gave me error

    The term '????' is not recognized as the name of a cmdlet, function,
    script file or operable program...
    

    As I found out later there was a problem with bad encoding. I found somewhere another approach and when I combined those two, I got working PS command:

    $Base64 = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes([System.IO.File]::ReadAllText("script.ps1")))
    

    Then I can redirect the result to file:

    $Base64 > base64Script.txt
    

    from where I just copy the encoded command and paste it here instead of :

    powershell.exe -EncodedCommand 
    

    and it works without any problem.

提交回复
热议问题