Add-History

 

Additional Resources For Add-History

 

Restoring a Previously-Saved Windows PowerShell History

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/add-history.mspx

 

 

SYNOPSIS

Appends entries to the session history.

 

SYNTAX

Add-History [[-inputObject] <PSObject[]>] [-passthru] [<CommonParameters>]

 

DETAILED 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 Get-Historyto get the commands and pass them to Add-History, or 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.

 

PARAMETERS

 

-inputObject <PSObject[]>

Adds the specified HistoryInfo objects to the session history. You can use this parameter to submit a HistoryInfo object from Get-History, Import-Clixml, or Import-Csv to Add-History.

 

Required?

false

Position?

1

Default value

 

Accept pipeline input?  

true (ByValue)

Accept wildcard characters? 

false

 

-passthru <SwitchParameter>

Passes the object created by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

HistoryInfo object

 

NOTES

 

For more information, type "Get-Help Add-History -detailed". For technical information, type "Get-Help Add-History -full".

 

To specify the commands to add to the history, use the -InputObject parameter. The Add-History command accepts only HistoryInfo objects, such as those generated for each command by Get-History. You cannot pass it a path and file name or a list of commands.

 

You can use the -InputObject parameter to pass a file of HistoryInfo objects to Add-History. To do so, export the results of a Get-Historycommand to a file by using Export-Csvor Export-Clixmland then import the file by using Import-Csv or Import-Clixml. You can then pass the file of imported HistoryInfo object to Add-History through a pipeline or in a variable. For details, see the examples.

 

The file of HistoryInfo objects that you pass to Add-History must include the type information, column headings, and all of the properties of the HistoryInfo objects. If you intend to pass the objects back to Add-History, do not use the NoTypeInformation parameter of Export-Csvand do not delete the type information, column headings, or any fields in the file.

 

The session history is a list of the commands entered during the session, along with the ID, which represents the order of execution, the status, and start and end times of the command. As you enter each command, Windows PowerShell adds it to the history so that you can reuse it. For more information about the session history, type "get-help about_history".

 

You cannot clear the session history except by ending the Windows PowerShell session.

 

To edit the session history, export the session to a CSV or XML file, edit the file, import the file, and use Add-History to append it to the current session history.

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

EXAMPLE 1

 

get-history | export-csv c:\testing\history.csv

 

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-Csvcmdlet 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

 

import-clixml c:\temp\history.xml | add-history -passthru | invoke-history

 

This command imports commands in the History.xml file, adds them to the current session history, and then executes the commands. The first command uses the Import-Clixmlcommand 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 to the Invoke-History cmdlet, which executes the commands.

 

EXAMPLE 3

 

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.

 

EXAMPLE 4

 

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

 

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, Add-History does not generate any output to display.

 

EXAMPLE 5

 

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

 

RELATED LINKS

Get-History

Invoke-History