Powershell - Add-History Cmdlet



Cmdlet

Add-History cmdlet is used to add commands in current history.

In these example, we're see the Add-History cmdlet in action.

Example

In this example, we'll add first five history command to current history again.

> get-history
 Id CommandLine                                                                         
  -- -----------                                                                         
  13 clear-history                                                                       
  14 get-history                                                                         
  15 dir                                                                                 
  16 dir                                                                                 
  17 dir                                                                                 
  18 dir                                                                                 

> Get-history -count 5 | Add-history

Now get the history again to see the effect of Add-history.

> Get-history
 
 Id CommandLine                                                                         
  -- -----------                                                                         
  13 clear-history                                                                       
  14 get-history                                                                         
  15 dir                                                                                 
  16 dir                                                                                 
  17 dir                                                                                 
  18 dir                                                                                 
  19 get-history                                                                         
  20 get-history -count 5 | Add-history                                                  
  21 dir                                                                                 
  22 dir                                                                                 
  23 dir                                                                                 
  24 get-history                                                                         
  25 get-history -count 5 | Add-history 
powershell_advanced_cmdlets.htm
Advertisements