Copy the last powershell command to clipboard

By Andrei Ungureanu - Last updated: Wednesday, June 7, 2017 - Save & Share - Leave a Comment

Sunt situatii in care am testat o comanda in Powershell si dorim sa o copiem pentru a fi trimisa unui coleg sau pentru a fi pusa intr-un script. Iar cand este foarte lunga, a face select si copy/paste e un proces destul de lent. Solutia este sa folosim history-ul din Powershell (Get-History aka R) si comanda Clip.

(Get-History)[-1].CommandLine | Clip

In exemplul de mai sus a folosit Get-History cu proprietatea CommandLine si am redirectat totul catre comanda Clip.

Sau pe versiunile mai noi de Powershell (cred ca incepand cu v5) puteti folosi Set-Clipboard:

image

PS: si Start-Transcript este o solutie, doar sa il aveti activat la inceputul sesiunii.

Posted in Scripting • Tags: , Top Of Page

Write a comment