Lucas Kauffman
Lucas Kauffman

Reputation: 6881

Powershell append to file not appending string

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?

Upvotes: 1

Views: 242

Answers (1)

Avshalom
Avshalom

Reputation: 8889

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

appendTitle $filepath "Net Accounts"

Upvotes: 3

Related Questions