从另一个运行 PowerShell 脚本 [英] Run a PowerShell script from another one

查看:41
本文介绍了从另一个运行 PowerShell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从另一个脚本运行 PowerShell 脚本的最佳和正确方法是什么?

What is the best and correct way to run a PowerShell script from another one?

我有一个脚本 a.ps1,我想从中调用执行不同任务的 b.ps1.

I have a script a.ps1 from which I want to call b.ps1 which does different task.

让我知道您的建议.点采购是这里的最佳选择吗?

Let me know your suggestions. Is dot sourcing is the best option here?

推荐答案

点源将运行第二个脚本,就好像它是调用者的一部分——所有脚本范围的更改都会影响调用者.如果这是你想要的,那么点源,

Dot sourcing will run the second script as if it is part of the caller—all script scope changes will affect the caller. If this is what you want then dot-source,

然而,更常见的是将另一个脚本当作函数来调用(脚本可以像函数一样使用 param 和函数级属性).在许多方面,脚本是一个 PowerShell 函数,文件名取代了函数的命名.

However it is more usual to call the other script as if it were a function (a script can use param and function level attributes just like a function). In many ways a script is a PowerShell function, with the name of the file replacing the naming of the function.

这篇关于从另一个运行 PowerShell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆