Windows PowerShell Command history usage

Source: Internet
Author: User

(i) Get all cmdlets that contain the "history" keyword

Using the PS c:\< get-command-name *history*-commandtype cmdlet, the result.

650) this.width=650; "title=" clipboard "style=" Border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard "Src=" http://s3.51cto.com/wyfs02/M01/5A/33/wKioL1T5pZHDfKMxAAC3v38aiP8741.jpg "height=" 123 "/>

(b) After finding a history-related command, we can then use the get-history to get a historical record of the command.

650) this.width=650; "title=" clipboard[1] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [1] "src=" http://s3.51cto.com/wyfs02/M02/5A/33/wKioL1T5pZPxWlvBAACVplncRN0541.jpg "height=" 187 "/>

(iii) The alias of the cmdlet can be obtained by using the Get-alias-definition Get-history method.

650) this.width=650; "title=" clipboard[2] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [2] "src=" http://s3.51cto.com/wyfs02/M00/5A/33/wKioL1T5pZWAqrS0AAB23X2flfw651.jpg "height=" 122 "/>

(d) How to run a history command by checking the command history information you see?

For example, the command recorded above has Get-childitem, the Id number of this command history is 3, then we can run this historical command by using PS c:\< Invoke-history-id.

650) this.width=650; "title=" clipboard[3] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [3] "src=" http://s3.51cto.com/wyfs02/M02/5A/37/wKiom1T5pIGQpqs0AAD5AZKEUyk789.jpg "height=" 241 "/>

(v) How can I view a specific command history?

You can get the command history with ID number 3 and 4 by using the get-history ID number.

650) this.width=650; "title=" clipboard[4] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [4] "src=" http://s3.51cto.com/wyfs02/M01/5A/33/wKioL1T5pZqy33y5AABQLycfkEA659.jpg "height=" 121 "/>

But can not use Invoke-history-id 3,4 way to run, otherwise will error,.

650) this.width=650; "title=" clipboard[5] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [5] "src=" http://s3.51cto.com/wyfs02/M01/5A/37/wKiom1T5pIfTOTVCAAC5oFX3rvk898.jpg "height="/>

The same,

We can use Get-history 3 | Invoke-history Way to carry out the historical command,.

650) this.width=650; "title=" clipboard[6] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [6] "src=" http://s3.51cto.com/wyfs02/M02/5A/37/wKiom1T5pI-QVzZiAADUxJ38fVo743.jpg "height="/>

But

Cannot use get-history 3,4 | Invoke-history the way to execute the order, otherwise it will error,.

650) this.width=650; "title=" clipboard[7] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [7] "src=" http://s3.51cto.com/wyfs02/M01/5A/33/wKioL1T5pa7xvo15AADBQtBTNSE676.jpg "height=" 104 "/>

Through the error can be seen that the pipeline can not accept the input of multiple projects at the same time, we can add a Foreach Loop statement to solve the problem.

Use the command:

Get-history-id 3, 4 | foreach {Invoke-history-id $_.id}

The command executed successfully.

650) this.width=650; "title=" clipboard[8] "style=" border-top:0px;border-right:0px;background-image:none; border-bottom:0px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px, "border=" 0 "alt=" clipboard [8] "src=" http://s3.51cto.com/wyfs02/M01/5A/37/wKiom1T5pJ_jxUF9AAENcIlsMYs201.jpg "height=" 296 "/>

Tip: http://blogs.technet.com/b/heyscriptingguy/archive/2015/03/03/avoid-scripting-use-powershell-command-history.aspx

==============================================================================

This article from "Zeng Hung Xin Technical column" blog, declined to reprint!

Windows PowerShell Command history usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.