PowerShell Logo Small

Get-History



This is the built-in help made by Microsoft for the command 'Get-History', in PowerShell version 4 - as retrieved from Windows version 'Microsoft Windows 8.1 Enterprise' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Gets a list of the commands entered during the current session.

SYNTAX


Get-History [[-Id] <Int64[]>] [[-Count] <Int32>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Get-History cmdlet gets the session history, that is, the list of commands entered during the current session.


Windows PowerShell automatically maintains a history of each session. The number of entries in the session history is determined by the value of the $MaximumHistoryCo
unt preference variable. Beginning in Windows PowerShell 3.0, the default value is 4096.


You can save the session history in XML or CSV format. By default, history files are saved in the home directory, but you can save the file in any location.


For more information about the history features in Windows PowerShell, see about_History (http://go.microsoft.com/fwlink/?LinkID=113233).



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=289585
Add-History
Clear-History
Invoke-History
about_History

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>Get-History



This command gets the entries in the session history. The default display shows each command and its ID, which indicates the order of execution.








-------------------------- EXAMPLE 2 --------------------------

PS C:\>Get-History | Where-Object {$_.CommandLine -like "*Service*"}



This command gets entries in the command history that include "service". The first command gets all entries in the session history. The pipeline operator (|) passes t
he results to the Where-Object cmdlet, which selects only the commands that include "service".








-------------------------- EXAMPLE 3 --------------------------

PS C:\>Get-History -ID 7 -Count 5 | Export-Csv History.csv



This command gets the five most recent history entries ending with entry 7. The pipeline operator (|) passes the result to the Export-Csv cmdlet, which formats the hi
story as comma-separated text and saves it in the History.csv file. The file includes the data that is displayed when you format the history as a list, including the
status and start and end times of the command.








-------------------------- EXAMPLE 4 --------------------------

PS C:\>Get-History -Count 1



This command gets the last (most recently entered) command in the command history. It uses the Count parameter to display just one command. By default, Get-History ge
ts the most recent commands. This command can be abbreviated to "h -c 1" and is equivalent to pressing the up-arrow key.








-------------------------- EXAMPLE 5 --------------------------

PS C:\>Get-History | Format-List -Property *



This command displays all of the properties of entries in the session history. The pipeline operator (|) passes the results of a Get-History command to the Format-Lis
t cmdlet, which displays all of the properties of each history entry, including the ID, status, and start and end times of the command.