In che modo è possibile aggiungere timestamp a ciascuna riga di un output generato dall'operatore &
PowerShell?Come aggiungere timestamp alle singole righe di PowerShell e output?
Esempio:
PS H:\> $result = & ping 192.168.1.1
PS H:\> echo $result
Pinging 192.168.1.1 with 32 bytes of data:
Reply from 192.168.1.1: bytes=32 time=104ms TTL=250
Reply from 192.168.1.1: bytes=32 time=106ms TTL=250
Reply from 192.168.1.1: bytes=32 time=102ms TTL=250
Reply from 192.168.1.1: bytes=32 time=102ms TTL=250
Ping statistics for 192.168.1.1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 102ms, Maximum = 106ms, Average = 103ms
risultato desiderato:
PS H:\> echo $result
2014-12-08T14:45:48.8898125+00:00:Pinging 192.168.1.1 with 32 bytes of data:
2014-12-08T14:45:48.8932661+00:00:Reply from 192.168.1.1: bytes=32 time=104ms TTL=250
2014-12-08T14:45:48.9233451+00:00:Reply from 192.168.1.1: bytes=32 time=106ms TTL=250
2014-12-08T14:45:48.9765438+00:00:Reply from 192.168.1.1: bytes=32 time=102ms TTL=250
2014-12-08T14:45:49.0233105+00:00:Reply from 192.168.1.1: bytes=32 time=102ms TTL=250
2014-12-08T14:45:49.0233201+00:00:
2014-12-08T14:45:49.0238753+00:00:Ping statistics for 192.168.1.1:
2014-12-08T14:45:49.0239210+00:00: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
2014-12-08T14:45:49.0233318+00:00:Approximate round trip times in milli-seconds:
2014-12-08T14:45:49.0237209+00:00: Minimum = 102ms, Maximum = 106ms, Average = 103ms
so come dividere/partecipare a una serie di PowerShell, ma questo può avvenire solo dopo che l'operatore &
completa. Sto cercando una soluzione più in tempo reale, in cui i timestamp vengono aggiunti all'output mentre l'operatore & è in esecuzione.
Tra l'altro, il timestamp stesso è $($(Get-Date -Format o) + ":")
La mia domanda era su come aggiungere timestamp per l'uscita nel primo posizionare, non come filtrarli in (o out) successivamente. –
Ecco cosa sta facendo il filtro. Un filtro PowerShell è un blocco di script che accetta l'input dalla pipeline e viene eseguito una volta per ogni oggetto che ottiene dalla pipeline. Funzionalmente è uguale a una funzione con solo un blocco di processo. Questo filtro aggiungerà il timestamp a ciascun output di riga dal tuo eseguibile. – mjolinor
Ah, in effetti, funziona esattamente come hai descritto. Grazie mille! Problema risolto! –