gpt4 book ai didi

powershell - 开始工作中无法识别的功能

转载 作者:行者123 更新时间:2023-12-03 00:26:52 25 4
gpt4 key购买 nike

我在模块 sysinfo.psm1 中创建了一个函数“Get-Uptime”并导入了该模块。

C:/pstools> get-command -Module sysinfo

CommandType Name Definition
----------- ---- ----------
Function Get-Uptime ...

该功能在 Powershell 中运行良好。但是,每当我在 Start-job -scriptblock {Get-Uptime $servernae} 中使用 Get-Uptime 函数时,作业都会失败并出现以下错误
Receive-Job : The term 'get-uptime' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and
try again.

有人可以让我知道我错过了什么吗?我在网上搜索并找到了在脚本 block 中编写所有代码而不是使用函数的建议,但我尝试过并遇到了类似的错误。

谢谢你。

最佳答案

您可以使用 初始化脚本 导入模块:

PS II> Start-Job -InitializationScript {import-module "c:\module.psm1"} -script {Uptime}

关于powershell - 开始工作中无法识别的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12293701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com