Skip to the main content.

PowerShell Tips

Harvest PowerShell command history

Table of contents

Post Featured Image

Tobias & Aleksandar's tip #9:

The two very well-known PowerShell experts have teamed up to share their best and most helpful PowerShell tips.

We will be publishing their scripts over the course of Scriptember in 13 blog posts. Don't miss their insights! Be sure to follow all Scriptember events, listed in our calendar here

 

Overview of all 13 articles published during Scriptember

 

 

Harvest command history

If you played interactively with PowerShell and then discovered that you’d like to keep the code that you just executed, here is a useful line:


(Get-History).CommandLine | Set-ClipBoard 


It copies your entire command line history to the clipboard so you can easily paste it to your favorite editor and save it.

If your history is very large, you can add time filtering. This will get you just the commands from the past 15 minutes:


(Get-History | Where-Object StartExecutionTime -gt (Get-Date).AddMinutes(-15)).CommandLine | Set-ClipBoard 

 

 

 

Good2know


Scriptember! Stay tuned:

During Scriptember, our calendar provides the best possible overview.  

Scriptember - hier ist die Übersicht

 

  • Follow us on social media, look for and use the hashtags #Scriptember and #PowerShell.
  • Join our live sessions, overview soon here.
  • Participate in challenges and contests. 
  • Share your knowledge.

 

Find all events here!

 

 

Related links 



Related posts

7 min read

Hidden configuration variables in PowerShell

Tobias & Aleksandar's tip #13:

The two very well-known PowerShell experts have teamed up to share their best and most...

4 min read

Hiding confirmations in PowerShell

Tobias & Aleksandar's tip #12:

The two PowerShell experts have teamed up to share their best and most helpful...

4 min read

URL Encoding in PowerShell

Tobias & Aleksandar's tip #11:

The two very well-known PowerShell experts have teamed up to share their best and most...

About the author: