IT Questions and Answers :)

Wednesday, May 15, 2019

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 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.
  • Copies the entire command history in the current shell session to the clipboard.

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

https://ss64.com/ps/get-history.html
Share:

0 comments:

Post a Comment

Popular Posts