IT Questions and Answers :)

Friday, February 19, 2021

In Powershell, what does the command "(get-history)[-1].commandLine | clip" do?

 In Powershell, what does the command "(get-history)[-1].commandLine | clip" do?

  • Clears the entire command history in the current shell session.
  • Copies the entire command history in the current shell session to the clipboard.
  • Copies the last-issued command in the current shell session to the clipboard.
  • Clears the last-issued command in the command history in the current shell session.     
In Powershell, what does the command "(get-history)[-1].commandLine | clip" do?

EXPLANATION

Get-History - Get a list of the commands entered during the current session.  Returns a HistoryInfo object for each history item that it gets.

Powershell About Arrays - "Negative numbers count from the end of the array. For example, '-1' refers to the last element of the array."  

HistoryInfo.CommandLine Property - Returns the command line string that was issued for that command history item

clip -  Windows Vista included a tiny command line utility called clip. All it does is paste its stdin onto the clipboard.  (Not actually a Powershell command so can be used in Command Prompt as well.

SOURCE

Share:

0 comments:

Post a Comment

Popular Posts