views:

383

answers:

2

Hi Guys,

So Im being a bit anal here but I cant get add-content to add both a string and the output of a cmdlet so it would look something like this;

Add-content -path $logfile -value "This is my text"+(Get-Date)

I realise I can just add another line to set a variable to the result of get-date but and then pass the variable into my add-content command but I just wondered if I could do it in a single line, like a said Im being anal lol

Cheers

Andy

+7  A: 

Try "This is my text $(Get-Date)"

Mohit Chakraborty
Nice work, Im I right in saying the $ puts PS back into expression mode?
Andy Walker
Right, $() makes PS evaluate expressions inside strings with double quotes.
Mohit Chakraborty
+4  A: 

I prefer MohitC method but you can also enclose your value in parenthesis:

Add-content -path $logfile -value ("This is my text "+(Get-Date))

Shay Levy