【发布时间】:2020-03-11 14:36:59
【问题描述】:
我在脚本块中使用文件中的函数时遇到问题。
函数文件名:functions.ps1.
我更喜欢在文件中使用函数,通常它是有效的。 但是在我用于作业的脚本块中,我有错误。 你能帮我在脚本块中使用函数吗?
. .\functions.ps1
$ip = "10.0.0.24"
$scriptblock = { get-ostype -ip $args[0] }
Start-Job -name "name" -ScriptBlock $scriptblock -ArgumentList $ip
作业出错:
术语“get-ostype”未被识别为 cmdlet、函数的名称, 脚本文件或可运行的程序。检查名称的拼写,或者如果 路径已包含,请验证路径是否正确,然后重试。 + CategoryInfo : ObjectNotFound: (get-ostype:String) [], CommandNotFoundException +fullyQualifiedErrorId:CommandNotFoundException + PSComputerName:本地主机【问题讨论】:
-
只需将文件加载到您的脚本块中。
$scriptblock={. <pathToFile>\functions.ps1; get-ostype -ip $args[0] }。作业范围不会继承当前范围中加载的函数。
标签: function powershell jobs