0

I need to record some command lines inputs which are typed on cmd.exe program on Windows. I launch it from a PowerShell process, so I try this method explained here :

PS (location)> cmd.exe | Tee-Object -file Cmd.exe.log

It's getting closer but I need to get this...

  • How to record ONLY the typed command, not the output?

  • How to see the prompt cursor, how to keep the "arrow" special command thrown with the keyboard recalling the previous commands?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38

1 Answers1

0

There is Start-Trascript which logs all the commands you entered. More in official documentation: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-6

The full output of the example trace is

**********************
Windows PowerShell transcript start
Start time: 20190322104506
Username: DOMAIN\user
RunAs User: DOMAIN\user
Configuration Name: 
Machine: MAICHINE_NAME (Microsoft Windows NT 10.0.17763.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 31428
PSVersion: 5.1.17763.316
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.316
BuildVersion: 10.0.17763.316
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\transcripts\transcript0.txt

C:\projects\> ls


    Directory: C:\projects\


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       03/01/2019     16:07                X
d-----       18/02/2019     16:56                Y
d-----       21/03/2019     15:49                Z
d-----       22/03/2018     16:17                T


C:\projects\> cat .\paket.lock
STORAGE: NONE

C:\projects\> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20190322104539
**********************

Piotr Stapp
  • 19,392
  • 11
  • 68
  • 116
  • Thanks to *Piotr Stapp* but the expected log needed : 1) **isn't** the powershell commands list but the cmd.exe commands list ; 2) The **output result isn't** either expected. – François Gardien Mar 22 '19 at 10:18
  • @FrançoisGardien filtering input and output is easy (just grep), but as far I know cmd doesn't have such logging. Why you cannot invoke commands in powershell? – Piotr Stapp Mar 22 '19 at 10:28
  • I didn't expect to use some powershell commands but I try it : it's working with my javascript framework ! Moreover I don't find in this documentation syntax how to filter only the input commands, what could you advice to me ? – François Gardien Mar 23 '19 at 13:04
  • It's OK to use powershell rather than cmd to launch some frameworks, but I don't find in the documentation how to use grep to get only the input ? Can you provide an example ? – François Gardien Mar 25 '19 at 15:24
  • An example: cat .\transcript0.txt | Select-String "^C\:\\projects\\" – Piotr Stapp Mar 25 '19 at 15:34
  • 1
    Thanks, it works like a charm, I only changed the destination : PS (location)>.\dayLogs.log | Select-String "^C\:" > inputsOfDay.log – François Gardien Mar 27 '19 at 11:27