在powershell中使用get-date来创建日志字符串

Nai*_*gel 9 powershell getdate

我在脚本中使用这些行来写一些我最终放在日志文件中的信息.

$log = "some text: "
$log += Get-Date
$log += "; some text"
Run Code Online (Sandbox Code Playgroud)

这样我就能正确获取数据,所以我的输出就是some text: 02/13/2013 09:31:55; some text.有没有更短的方法来获得这个结果?我的意思是这样的(实际上不起作用)

$log = "some text: " + Get-Date + "; some text"
Run Code Online (Sandbox Code Playgroud)

CB.*_*CB. 22

尝试:

$log = "some text: $(Get-Date); some text"
Run Code Online (Sandbox Code Playgroud)

$()函数或变量的属性es:$($ myvar.someprop)在字符串中的扩展值.