简体   繁体   中英

Trying to compile the powershell script to exe with parameters

Im looking to convert my ps1 to 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. 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. 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. after that i used ps2exe script to compile it to exe

My Solution was:

  1. Create Template script, whatever needed to be changed from the template mark as something like '@@@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.
  4. Compile the newly created script with Ps2Exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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