How to export PowerShell command history to a file

by [Published on 28 Aug. 2014 / Last Updated on 28 Aug. 2014]

Tip explains how to export PowerShell command history to a file for re-use.

PowerShell maintains session history to store commands executed in the current PowerShell session. The command history is lost when you close the PowerShell window. You can use the Get-History PowerShell cmdlet to export commands to a file as shown below:

  • Get-History | Export-CSV C:\Temp\CommandHistory.CSV

The above command gets all PowerShell commands from the session history and Export-CSV cmdlet is used to export the output in a CSV file.

About Nirmal Sharma

Nirmal is a MCSEx3, MCITP and was awarded Microsoft MVP award in Directory Services. He is specialized in Directory Services, Microsoft Clustering, Hyper-V, SQL and Exchange and has been involved in Microsoft Technologies since 1994. In his spare time, he offers technical help by writing tips and articles. Nirmal can be reached at nirmal_sharma@mvps.org.

The Author — Nirmal Sharma

Nirmal Sharma avatar

Nirmal is a MCSEx3, MCITP and was awarded Microsoft MVP award in Directory Services and Windows Networking. He is specialized in Directory Services, Microsoft Clustering, Hyper-V, SQL and Exchange and has been involved in Microsoft Technologies since 1994.

Latest Contributions

Featured Links