Adding Powershell

So, I have a little anal here, but I can’t get add-content to add both the string and the output of the cmdlet so that it looks something like this:

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

I understand that I can just add another line to set the variable to the get-date result and then pass the variable to my add-content command, but I'm just wondering if I can do this on one line, for example, I said that Im - anal lol

Greetings

Andy

+3
source share
2 answers

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

In PowerShell, double-quoted strings can contain variables and expressions. If this is not a simple expression (e.g. "This is a $value"), you need to wrap the expression in $()(e.g., "This is a $($value + 1)").

, " " escape- .

+15

MohitC, :

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

Source: https://habr.com/ru/post/1704620/


All Articles