[PowerShell][Example][101] - PowerShell Command history

[PowerShell][Example][101] - PowerShell Command history

This is a PowerShell basics, so this will be short, its helpful and I'm surprised on the number of people who don't know about command history. Most people hit up and down trying to find something that they previously ran, but a potentially much more useful method is as follows:

PS C:\Users\...> get-history
  Id CommandLine
  -- -----------
   1 cls
   2 Get-ChildItem
   3 get-history
   4 cls

PS C:\Users\...> invoke-history 2
Get-ChildItem

    Directory: C:\Users\...

So just like that, run "Get-History" and you'll get a list of commands that you've run. Then "Invoke-History" will run the specified line.

Happy Scripting,

Robert!


Robert, thanks for sharing!

Like
Reply

To view or add a comment, sign in

More articles by Robert Waltzing

Explore content categories