Reputation: 495
I am receiving the following error message:
Cannot bind argument to parameter 'FilePath' because it is an empty string.
from this code:
$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"
}
I've tried with and without the quotes, what am I doing wrong?
Edit: I've tried to echo the value and it existing but when I ran it in the log_message command it says its null/empty string.
Upvotes: 2
Views: 1755
Reputation: 3918
Your code does not work for me since your not using the word "function" to create the two functions: function cleanup(..) instead of just cleanup(..) and you should put the functions before calling it in your script.
I've changed your code as follows and it works now:
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
Upvotes: 3