Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 将参数传递给函数:无法将参数绑定到参数_Powershell - Fatal编程技术网

Powershell 将参数传递给函数:无法将参数绑定到参数

Powershell 将参数传递给函数:无法将参数绑定到参数,powershell,Powershell,我收到以下错误消息: 无法将参数绑定到参数“FilePath”,因为它是空字符串 根据该代码: $image = "image" $logfile_name = "log.txt" cleanup $image $logfile_name function cleanup($image, $logfile) { log_message "message" $logfile } function log_message($msg, $logfile) { $msg | Tee-

我收到以下错误消息:

无法将参数绑定到参数“FilePath”,因为它是空字符串

根据该代码:

$image = "image"
$logfile_name = "log.txt"

cleanup $image $logfile_name

function cleanup($image, $logfile) {
   log_message "message" $logfile
}

function log_message($msg, $logfile) {
    $msg | Tee-Object -Append -FilePath "$logfile"
}
我试过引用和不引用,我做错了什么


编辑:我试图回显该值,但当我在log_message命令中运行它时,它会显示其null/空字符串。

您的代码不适用于我,因为您没有使用“function”一词创建两个函数:function cleanup(..)而不是cleanup(..)在脚本中调用函数之前,应该先放置函数

我已按如下方式更改了您的代码,现在可以使用了:

function cleanup($image, $logfile) {
   log_message "message" $logfile
}

function log_message($msg, $logfile) {
    $msg | Tee-Object -Append -FilePath "$logfile"
}

$image = "image"
$logfile_name = "log.txt"

cleanup $image $logfile_name

您的代码不适用于我,因为您没有使用单词“function”来创建这两个函数。函数清理(..)而不仅仅是清理(..),你应该在脚本中调用它之前放置函数。@Vivekkumarsing,这就是我的目标,如果不存在,它应该创建文件。这是一个打字错误,我很抱歉,我已经用函数关键字编写了代码是的,是函数顺序改变了吗?脚本从上到下执行。因此,在调用函数之前,需要先创建它。