add date as a column

This topic contains 2 replies, has 2 voices, and was last updated by  Mark 4 months ago.

  • Author
    Posts
  • #77469

    Mark
    Participant

    Hello all users of this forum,
    I'm new here and powershell too:)

    I write a simple code to list open file on the file server:

     get-smbopenfile | Where-object -property path -like "*com*" | ft ClientUsername, path -wrap -autosize 

    but I need also an actual date and time in additional column, I'm trying as below but it didn't work

     get-smbopenfile | Where-object -property path -like "*com*" | ft ClientUsername, path, get-date -wrap -autosize 

    Can I ask for any suggestions?
    Thx

  • #77470

    Don Jones
    Keymaster

    You're close. There's actually an example of the correct syntax in the help for Format-Table. It's Example 5 https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-table?view=powershell-5.1

  • #77473

    Mark
    Participant
    get-smbopenfile | Where-object -property path -like "*com*" | ft ClientUsername, path, @{Label="time"; Expression={(Get-Date) }} -wrap -autosize 

    Thx Mr Don Jones it did the job

You must be logged in to reply to this topic.