about_History
適用対象: Windows PowerShell 2.0, Windows PowerShell 3.0
トピック
about_History
概要
コマンド履歴のコマンドを取得し、実行する方法について説明します。
詳細説明
Windows PowerShell® では、コマンド プロンプトにコマンドを入力すると、そのコマンドがコマンド履歴に保存されます。履歴内のコマンドは、作業の記録として使用できます。また、コマンド履歴からコマンドを呼び出して実行することができます。
History コマンドレット
Windows PowerShell には、コマンド履歴を管理する一連のコマンドレットが用意されています。
Cmdlet (Alias) Description
------------------- ------------------------------------------
Get-History (h) Gets the command history.
Invoke-History (r) Runs a command in the command history.
Add-History Adds a command to the command history.
Clear-History (clh) Deletes commands from the command history.
履歴を管理するためのキーボード ショートカット
Windows PowerShell コンソールで、次のショートカットを使用してコマンド履歴を管理することができます。
その他のホスト アプリケーションについては、製品のドキュメントを参照してください。
Use this key To perform this action
------------- ----------------------------------------------
UP ARROW Displays the previous command.
DOWN ARROW Displays the next command.
F7 Displays the command history.
To hide the history, press ESC.
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
$MaximumHistoryCount ユーザー設定変数は、Windows PowerShell によってコマンド履歴に保存されるコマンドの最大数を決定します。既定値は 4096 です。つまり、Windows PowerShell は、4096 個の最新のコマンドを保存します。この変数の値は変更できます。
たとえば、次のコマンドは、$MaximumHistoryCount をコマンド 100 個に減らします。
$MaximumHistoryCount = 100
設定を適用するには、Windows PowerShell を再起動します。
すべての Windows PowerShell セッションに新しい変数値を保存するには、代入ステートメントを Windows PowerShell プロファイルに追加します。プロファイルの詳細については、「about_Profiles」(https://go.microsoft.com/fwlink/?LinkID=113729) を参照してください。
$MaximumHistoryCount ユーザー設定変数の詳細については、「about_Preference_Variables」(https://go.microsoft.com/fwlink/?LinkID=113248) を参照してください。
注記:
Windows PowerShell 2.0 では、$MaximumHistoryCount ユーザー設定変数の既定値は 64 です。
履歴内のコマンドの順序
コマンドが履歴に追加されるのは、コマンドが入力されたときではなく、コマンドの実行完了時です。コマンドが完了するまで時間がかかる場合や、コマンドが入れ子になったプロンプトで実行されている場合は、コマンドが履歴にばらばらに表示される可能性があります (入れ子になったプロンプトで実行されているコマンドが完了するのは、そのプロンプト レベルから抜けるときです)。
関連項目
about_Objects
about_Preference_Variables
about_Profiles
about_Variables