远程调用命令-找不到函数cmdlet



我得到了以下脚本:

param(
[string[]]$servers
)
function Write-Info($message) {
}
function Introspect($server) {
Write-Info "about to do something on server"    
// other powershell stuff that works
}
Foreach ($server in $servers) {
Invoke-Command -ComputerName $server -ScriptBlock ${function:Introspect} -ArgumentList $server -credential 'MyUser'
}

我正试图在远程服务器上调用(来自powershell(:

.myscript.ps1 server1,server2,server3

脚本正在执行,但问题是我收到了一个与Write-Info函数有关的错误,如下所示:

The term 'Write-Info' is not recognised as the name of a cmdlet, function, script file, or operable program

如果我将函数嵌入其中,Introspect函数可以正常工作,但我想它与不在远程服务器上的函数有关。

请问我该怎么解决?

通过在工作函数中嵌入"缺失"函数来解决此问题:

param(
[string[]]$servers
)
function Introspect($server) {
function Write-Info($message) {
}
Write-Info "about to do something on server"    
// other powershell stuff that works
}
Foreach ($server in $servers) {
Invoke-Command -ComputerName $server -ScriptBlock ${function:Introspect} -ArgumentList $server -credential 'MyUser'
}

相关内容

  • 没有找到相关文章

最新更新