1

I defined a function to append a title to an output file.

function appendTitle($filePath, [string]$title){

Add-Content -Path $filePath -Value "+------------------------+" 
Add-Content -Path $filePath -Value $title 
Add-Content -Path $filePath -Value "+------------------------+" 


}

The issue is that if I run it as such:

appendTitle($filePath, "Net Accounts")

But in the output file it doesn't include the $title variable but just displays:

+------------------------+

+------------------------+

So where did my variable go that I wanted to append?

1 Answer 1

3

It's Because you run it inside a parentheses, run it like that:

appendTitle $filepath "Net Accounts"
Sign up to request clarification or add additional context in comments.

1 Comment

More info: What the function is expecting is 2 arguments, a $filepath argument, which isn't typed so it could be anything, and a $title argument which it expects to be a string. What you pass is 1 argument, which is an array of two thing, first is $filepath, and second is "Net Accounts", and no second argument at all.

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.