How to create a dynamic variable in Powershell, sucha as date/time etc

后端 未结 5 950
太阳男子
太阳男子 2020-12-22 08:20

Hi i am not exactly sure if my wording is right but i need a variable which contains current date/time whenever i write data to log ; how can i do that with

5条回答
  •  清酒与你
    2020-12-22 08:40

    Why not use:

    Add-Content $LogFile -Value "$((Get-Date).DateTime): XXXXX"
    

    This gets the current datetime every time. Notice that it's inside $( ) which makes powershell run the expression(get the datetime) before inserting it into the string.

提交回复
热议问题