PowerShell Logo Small

Add-History



This is the built-in help made by Microsoft for the command 'Add-History', in PowerShell version 3 - as retrieved from Windows version 'Microsoft Windows Server 2012 Standard' 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

Appends entries to the session history.

SYNTAX


Add-History [[-InputObject] <PSObject[]>] [-Passthru] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Add-History cmdlet adds entries to the end of the session history, that is, the list of commands entered during the current session.


You can use the Get-History cmdlet to get the commands and pass them to Add-History, or you can export the commands to a CSV or XML file, then
import the commands, and pass the imported file to Add-History. You can use this cmdlet to add specific commands to the history or to create a
single history file that includes commands from more than one session.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkID=113279
Clear-History
Get-History
Invoke-History
about_History

REMARKS

<

Examples


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

PS C:\>get-history | export-csv c:\testing\history.csv
PS C:\>import-csv history.csv | add-history



These commands add the commands typed in one Windows PowerShell session to the history of a different Windows PowerShell session. The first
command gets objects representing the commands in the history and exports them to the History.csv file. The second command is typed at the
command line of a different session. It uses the Import-Csv cmdlet to import the objects in the History.csv file. The pipeline operator passes
the objects to the Add-History cmdlet, which adds the objects representing the commands in the History.csv file to the current session history.








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

PS C:\>import-clixml c:\temp\history.xml | add-history -passthru | foreach-object -process {invoke-history}



This command imports commands from the History.xml file, adds them to the current session history, and then executes the commands in the
combined history.

The first command uses the Import-Clixml cmdlet to import a command history that was exported to the History.xml file. The pipeline operator
(|) passes the commands to the Add-History parameter, which adds the commands to the current session history. The PassThru parameter passes
the objects representing the added commands down the pipeline.

The command then uses the ForEach-Object cmdlet to apply the Invoke-History command to each of the commands in the combined history. The
Invoke-History command is formatted as a script block (enclosed in braces) as required by the Process parameter of the ForEach-Object cmdlet.








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

PS C:\>get-history -id 5 -count 5 | add-history



This command adds the first five commands in the history to the end of the history list. It uses the Get-History cmdlet to get the five
commands ending in command 5. The pipeline operator (|) passes them to the Add-History cmdlet, which appends them to the current history. The
Add-History command does not include any parameters, but Windows PowerShell associates the objects passed through the pipeline with the
InputObject parameter of Add-History.








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

PS C:\>$a = import-csv c:\testing\history.csv
PS C:\>add-history -inputobject $a -passthru



These commands add the commands in the History.csv file to the current session history. The first command uses the Import-Csv cmdlet to import
the commands in the History.csv file and store its contents in the variable $a. The second command uses the Add-History cmdlet to add the
commands from History.csv to the current session history. It uses the InputObject parameter to specify the $a variable and the PassThru
parameter to generate an object to display at the command line. Without the PassThru parameter, the Add-History cmdlet does not generate any
output.








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

PS C:\>add-history -inputobject (import-clixml c:\temp\history01.xml)



This command adds the commands in the History01.xml file to the current session history. It uses the InputObject parameter to pass the results
of the command in parentheses to the Add-History cmdlet. The command in parentheses, which is executed first, imports the History01.xml file
into Windows PowerShell. The Add-History cmdlet then adds the commands in the file to the session history.