PowerShell Logo Small

Add-History



This is the built-in help made by Microsoft for the command 'Add-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

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 im
port 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 sing
le history file that includes commands from more than one session.



<

RELATED LINKS

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

REMARKS

<

Examples


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

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

C:\PS>import-csv history.csv | add-history



Description
-----------
These commands add the commands typed in one Windows PowerShell session to the history of a different Windows PowerShell session. The first comma
nd gets objects representing the commands in the history and exports them to the History.csv file. The second command is typed at the command lin
e 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 t
o the Add-History cmdlet, which adds the objects representing the commands in the History.csv file to the current session history.








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

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



Description
-----------
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 command 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 obje
cts 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-H
istory command is formatted as a script block, which is enclosed in braces ({}) because ForEach-Object requires a script block even when there is
only one command to apply.








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

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



Description
-----------
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
.








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

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

C:\PS>add-history -inputobject $a -passthru



Description
-----------
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 th
e 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 gener
ate an object to display at the command line. Without the PassThru parameter, Add-History does not generate any output to display.








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

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



Description
-----------
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 Add-History. The command in parentheses, which is executed first, imports the History01.xml file into Windows Powe
rShell. Add-History then adds the commands in the file to the session history.