开发者

what is best approach to design multi-part Powershell script (and avoid using invoke-expression)

I'm trying to redesign current script, which is "meta-script" (consists of multiple subscript parts, calling each other in turn). First one is main runner.ps1 getting some external data, then loading definitions.json, with following structure:

[
   {
    "script": "modules/module1.ps1", 
    "name":"some script name", 
    "comment":"some comment here"
   }, 
    ...
]

Then runner.ps1 converts external data to somedata.json, outputs it to file, and calls each module from definitions.json with invoke-expression, passing path to somedata.json to the module.

Module loads json, convert it back to array of objects, and doing something with it. After module finishes its work, it converts results of work to json, and returns path to that json to runner.ps1.

After all modules finish their work, runner.ps1 collects all data, convert it from json to some objects, reformats it and emails me with results and comments.

The system works, but using inv开发者_如何学运维oke-expression is considered bad practice (and I understand why), but I can't find better approach to "meta-script" problem. Dot-sourcing doesn't seem to be better, because it doesn't prevent "sourcecode of trusted script changed" problem, which I think is root reason why invoke-expression is bad.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜