Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Getting history


You can recall the commands you typed in the PowerShell console using the Get-History cmdlet.

How to do it...

This is how to redisplay the console history:

  1. Open PowerShell ISE as an administrator.

  2. Run the following command:

    Get-History
    

How it works...

By default, PowerShell will keep 64 previous commands in the buffer and allow you to recall these commands when you run Get-History. The Get-History command will display the last 32 commands, but you can also specify how many lines you want to display by specifying the –Count parameter:

#get last 10
Get-History –Count 10

If you want to reexecute any of the commands that you see in your history, you can use the Invoke-History cmdlet and provide it with the history ID. For example, if you want to re-execute ID 7, you can use the following command:

Invoke-History –ID 7