标题: 将PowerShell脚本转成EXE文件
创建: 2019-07-02 17:33 更新: 链接: https://scz.617.cn/windows/201907021733.txt
参看
Convert Ps1 files to .exe using these tools https://windowsreport.com/convert-ps1-exe-files/
这里提到很多工具,我只测试了PS2EXE这一种。
https://gallery.technet.microsoft.com/scriptcenter/PS2EXE-Convert-PowerShell-9e4e07f1/file/134627/1/PS2EXE-v0.5.0.0.zip
$ powershell -ExecutionPolicy ByPass -File ps2exe.ps1 PS2EXE; v0.5.0.0 by Ingo Karstein (http://blog.karstein-consulting.com)
Usage:
powershell.exe -command "&'.\ps2exe.ps1' [-inputFile] '<file_name>'
[-outputFile] '<file_name>'
[-verbose] [-debug] [-runtime20] [-runtime30]"
inputFile = PowerShell script that you want to convert to EXE
outputFile = destination EXE file name
verbose = Output verbose informations - if any
debug = generate debug informations for output file
debug = generate debug informations for output file
runtime20 = this switch forces PS2EXE to create a config file for
the generated EXE that contains the "supported .NET
Framework versions" setting for .NET Framework 2.0
for PowerShell 2.0
runtime30 = this switch forces PS2EXE to create a config file for
the generated EXE that contains the "supported .NET
Framework versions" setting for .NET Framework 4.0
for PowerShell 3.0
runtime40 = this switch forces PS2EXE to create a config file for
the generated EXE that contains the "supported .NET
Framework versions" setting for .NET Framework 4.0
for PowerShell 4.0
lcid = Location ID for the compiled EXE. Current user
culture if not specified.
x86 = Compile for 32-bit runtime only
x64 = Compile for 64-bit runtime only
sta = Single Thread Apartment Mode
mta = Multi Thread Apartment Mode
noConsole = The resulting EXE file starts without a console window just like a Windows Forms app.
$ powershell -ExecutionPolicy ByPass -File NetLocalGroupGetMembers2.ps1 XXX\Administrator S-1-5-21-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxx-500
$ powershell -ExecutionPolicy ByPass -File ps2exe.ps1 -inputFile NetLocalGroupGetMembers2.ps1 -outputFile NetLocalGroupGetMembers2.exe -runtime20
$ NetLocalGroupGetMembers2.exe XXX\Administrator S-1-5-21-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxx-500