Describes how to get and run commands in the command history.
When you enter a command at the command prompt, PowerShell saves the command in the command history. You can use the commands in the history as a record of your work. And, you can recall and run the commands from the command history.
PowerShell has a set of cmdlets that manage the command history.
||Gets the command history.|
||Runs a command in the command history.|
||Adds a command to the command history.|
||Deletes commands from the command history.|
Keyboard Shortcuts for Managing History
In the PowerShell console, you can use the following shortcuts to manage the command history.
For other host applications, see the product documentation.
|Use this key||To perform this action|
|UP ARROW||Displays the previous command.|
|DOWN ARROW||Displays the next command.|
|F7||Displays the command history.|
|ESC||To hide the history.|
|F8||Finds a command. Type one or more characters, and then|
|press F8. For the next instance, press F8 again.|
|F9||Find a command by history ID. Type the history ID, and|
|then press F9. To find the ID, press F7.|
$MaximumHistoryCount preference variable determines the maximum number
of commands that PowerShell saves in the command history.
The default value is 4096, meaning that PowerShell saves the 4096 most recent commands, but you can change the value of the variable.
For example, the following command lowers the
$MaximumHistoryCount to 100
$MaximumHistoryCount = 100
To apply the setting, restart PowerShell.
To save the new variable value for all your PowerShell sessions, add the assignment statement to a PowerShell profile. For more information about profiles, see about_Profiles.
For more information about the $MaximumHistoryCount preference variable, see about_Preference_Variables.
NOTE: In Windows PowerShell 2.0, the default value of the
$MaximumHistoryCount preference variable is 64.
Order of Commands in the History
Commands are added to the history when the command finishes executing, not when the command is entered. If commands take some time to be completed, or if the commands are executing in a nested prompt, the commands might appear to be out of order in the history. (Commands that are executing in a nested prompt are completed only when you exit the prompt level.)
Chargement du commentaire...