简体   繁体   English

尝试将 powershell 脚本编译为带参数的 exe

[英]Trying to compile the powershell script to exe with parameters

Im looking to convert my ps1 to exe.我希望将我的 ps1 转换为 exe。 it has to be some kind of a compiler that can accept parameters since i would like this exe file to be a bit different some times.它必须是某种可以接受参数的编译器,因为我希望这个 exe 文件有时会有所不同。 for example i may have inside the script:例如我可能在脚本里面:

$var1 = 0
$password = 'blabla'

I would like to to make it possible to compile it with the possibility to change $var1 or $password WITHOUT making any change in the ps file.我希望能够在不更改 ps 文件的情况下更改 $var1 或 $password 来编译它。 is that possible?那可能吗?

**edit **编辑

After researching the subject, My goal was to make a template script and being able to manipulate the script and create more scripts from the template.在研究了这个主题之后,我的目标是制作一个模板脚本,并且能够操作脚本并从模板中创建更多的脚本。 in the template i had for examples variables of paths, usernames and so on.在模板中,我有路径、用户名等变量的示例。 so i created a template script, and then another script which goes into the template script, reads it and then us the -replace method to replace what is needed and create a new script.所以我创建了一个模板脚本,然后另一个脚本进入模板脚本,读取它,然后我们使用 -replace 方法来替换所需的内容并创建一个新脚本。 after that i used ps2exe script to compile it to exe之后我使用 ps2exe 脚本将其编译为 exe

My Solution was:我的解决方案是:

  1. Create Template script, whatever needed to be changed from the template mark as something like '@@@var1@@@'创建模板脚本,任何需要从模板标记更改为“@@@var1@@@”之类的东西
  2. Create another script to accept variables.创建另一个脚本来接受变量。
  3. Get-content of the template script and use -repalce method to replace what is needed in the template script.获取模板脚本的内容并使用 -repalce 方法替换模板脚本中需要的内容。
  4. Compile the newly created script with Ps2Exe使用 Ps2Exe 编译新创建的脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM