PowerShell-Output execution results like log

Source: Internet
Author: User
Recently in the PowerShell to do some of the regular daily work, want to get the results in real time, like Linux installation software, a piece of the real-time output to the console, so it is clear to see the results of each step of execution. The format is like this:
PS > 02/28/2018 13:35:43 Checking xxx service ....
02/28/2018 13:35:44 XXX service is stopped.
02/28/2018 13:35:45 starting XXX service ....
02/28/2018 13:35:46 XXX Service is started.

I am also a PowerShell beginner, at first in order to achieve this time in real time display, with a very stupid method, is each output statement before the definition of a time variable, this is too cumbersome, there must be a simple way to achieve. In the group asked a master, sure enough. PowerShell defines a variable in a way that is straightforward: $ (powershell-command).

For example: $ (get-date)

You can use it directly. The following is a complete example:

PowerShell-Output execution results like log

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.