2

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.

2
  • 2
    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. Commented Aug 2, 2018 at 10:55
  • @VivekKumarSingh, That's what I am aiming for, it should create the file if non existent Commented Aug 2, 2018 at 11:06

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

3 Comments

It's a typo my apologies, I've wrote my code with the function keyword
Yeah it does, is it the function order that did the change?
The script executes from the top to the bottom. So, before you can call a function, you need to create it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.