PowerShell Logo Small

Get-History



This is the built-in help made by Microsoft for the command 'Get-History', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' 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] <int>] [<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 automatical
ly maintains a history of each session. You can save the session history in XML or CSV format. By default, history files are saved in the home di
rectory, but you can save the file in any location.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113317
about_history
Invoke-History
Add-History
Clear-History

REMARKS

<

Examples


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

C:\PS>get-history



Description
-----------
This command gets the 32 most recently submitted commands. The default display shows each command and its ID, which indicates the order of execut
ion.








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

C:\PS>get-history | where-object {$_.commandLine -like "*service*"}



Description
-----------
This command gets entries from the command history that include the word, "service". The first command gets the 32 most recent entries in the ses
sion history. The pipeline operator (|) passes the results to the Where-Object cmdlet, which selects only the commands that include "service".








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

C:\PS>get-history -id 7 -count 5 | export-csv history.csv



Description
-----------
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 history as comma-separated text and saves it in the History.csv file. The file includes the data that is displayed when you fo
rmat the history as a list, including the status and start and end times of the command.








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

C:\PS>get-history -count 1



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








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

C:\PS>get-history -count $MaximumHistoryCount



Description
-----------
This command displays all of the commands saved in the session history. By default, $MaximumHistoryCount is 64, so this command can be abbreviate
d as "h -c 64".








-------------------------- EXAMPLE 6 --------------------------

C:\PS>get-history | format-list



Description
-----------
This command displays all of the properties of entries in the session history. The pipeline operator (|) passes the result to the Format-List cmd
let, which displays all of the properties of each history entry, including the ID, status, and start and end times of the command.