1

I have a variable called BB_NP and I want to add the contents of that (string) to an output text file with a date/time, so just a basic log file.

Add-Content -Path ".\LogFile.txt" -Value $(Get-Date) ($BB_NP)

Every time I try, no matter what combination (wrapping it or not wrapping, etc), it can only do one, and not both, I believe it's due to the two different types of data.

How can I have this write to a text file, the date/time and then concatenate the content of BB_NP variable?.

Thanks!.

1 Answer 1

4

Use an expandable string literal, "...":

Add-Content -Path ".\LogFile.txt" -Value "[$(Get-Date)] $BB_NP"
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you Mathias, working as expected!, cheers!.
double quotes don't make a string literal tho'
@sirtao A literal is any source code element that maps to some well defined runtime value. The source code syntax @{} is an empty hashtable literal. Perhaps you're confusing literal with verbatim (the label we might use to describe a single-quoted string literal)?
@MathiasR.Jessen yeah, looks like I'm guilty of using the wrong words. I blame it on -LiteralPath for leading me astray! Scoundrel of a parameter!
@sirtao It's actually correct to call it "a literal path" too - adjective vs. noun - I blame English ^_^

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.