question

GSPATEL avatar image
0 Votes"
GSPATEL asked GSPATEL answered

Powershell Quser Date time format

Hi,

I am trying to get the Last Logon Date and Time but I am getting only Date in "dd/MM/yyyy". Can anyone please point out how to get date in "dd/MM/yyyy hh:mm tt" format

Here is the code I have right now.

 function TBLDATA {
  $(quser.exe /server:$ServerAddr  2>&1 | findstr "Active") -replace "^[\s>]","" -replace "\s+","," | ConvertFrom-Csv -Header $Header | ForEach-Object {
  $dListItem = New-Object System.Windows.Forms.ListViewItem ($_.USER_NAME)
  $dListItem.Subitems.Add($_.SESSION_NAME) | Out-Null
  $dListItem.Subitems.Add($_.SESS_ID) | Out-Null
     $dListItem.Subitems.Add($_.STATUS) | Out-Null
         $dListItem.Subitems.Add($_.IDLETIME) | Out-Null
         $dListItem.Subitems.Add($_.LOGONTIME) | Out-Null
  $dList.Items.Add($dListItem) | Out-Null
  }
 }

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

GSPATEL avatar image
0 Votes"
GSPATEL answered

I Figured it out be changing

This

  $(quser.exe /server:$ServerAddr  2>&1 | findstr "Active") -replace "^[\s>]","" -replace "\s+","," | ConvertFrom-Csv -Header $Header | ForEach-Object {

To THIS

      $(quser.exe /server:$ServerAddr  2>&1 | findstr "Active") -replace '\s{2,}',',' | ConvertFrom-Csv -Header $Header | ForEach-Object  {
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.