shape
shape
shape
shape

PowerShell Get-History - Nero Blanco IT Migration Specialists

  • user-icon Twan van Beers
  • calendar-icon 20 February, 2020

One command that I love to use in PowerShell is Get-History. It retrieves all of the commands that you have run in this session. You can use the id and count parameters to pick a single command or a number of commands including and prior to the id

e.g. Get-History -id 10 -count 5 gets command lines 6 through to 10 inclusive.

You can then also combine that with Set-Clipboard to copy commands to the clipboard so you can paste them into something else. Note that you can use clip.exe but that doesn’t support UTF-8 whereas Set-Clipboard does

(Get-History -id 10 -count 5).commandline | Set-Clipboard

Now those commands are ready to just Paste wherever you like 🙂

Twan van Beers
Twan van Beers

Twan is a senior consultant with over 30 years of experience. He has a wide range of skills including Messaging, Active Directory, SQL, Networking and Firewalls. Twan loves to write scripts and get deep and dirty into debugging code, in order to understand and resolve the most complex of problems.

0 Comments

News & Insights

Trusted insights on technology and innovation to power your business growth.