add date as a column

Welcome Forums General PowerShell Q&A add date as a column

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 year, 3 months ago.

  • Author
    Posts
  • #77469

    Participant
    Points: 7
    Rank: Member

    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

    Keymaster
    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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

    Participant
    Points: 7
    Rank: Member
    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

The topic ‘add date as a column’ is closed to new replies.