Powershell one liners to include a timestamp.

Soldato
Joined
8 Mar 2005
Posts
3,674
Location
London, UK
Been struggling how to include a timestamp in a chained 1-liner in PS.

For example the following outputs two columns showing a count and the application name;
Code:
Get-XAsession | Select AccountName,BrowserName | Group Browsername | Sort Name | Select Count,Name | ft - auto

Count Name
----- -----
10 Appa
15 Appb

What I want to do is include is an additional column which with a timestamp when the 1-liner was ran; E.G.
TS Count Name
------------- ----- -----
01APR15-0900 10 Appa
01APR15-0900 15 Appb

The idea being this 1-liner will run hourly and append to a file.

Any help, pointers would be much appreciated.

EDIT - sorted via the following convoluted method;
Code:
Get-XASession | select @{Expression={get-date -f "dd-MM-yy HH:00:00"};label="Timestamp"},accountname,browsername | group timestamp, browsername | select @{Expression={$_.Name.Split(",")[0].Trim()};Label="Timestamp"},count,@{Expression={$_.Name.Split(",")[1].Trim()};Label="Name"} | sort name | ft timestamp,count,name  -auto -hidetableheaders | out-file \\Server\share\filename.txt -append
 
Last edited:
Back
Top Bottom