0

The Out-File lets us write output to a file. What if we want to write input to a file?

I want a list of all the commands that I wrote during a PowerShell session. The file should look something like this:

dir
cd
ni myFile.txt -t file
cd.. 

We want to keep track of what commands we use in PowerShell.

2 Answers 2

2

Try this:

Get-History |
 select -ExpandProperty commandline |
 Add-Content commandhistory.txt
Sign up to request clarification or add additional context in comments.

Comments

1

You could make use of Start-Transcript and Stop-Transcript

Technet links about each command: start-transcript and stop-transcript

Usage example: Start-Transcript -Path C:\Folder\Transcript.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.