PowerShell-output the execution result like Log
Recently, I have been using Powershell to complete some daily work that I often have to do. I want to get the implementation results in real time, just like Linux installation software, which can be output to the console in real time, so that I can clearly see the implementation results of each step. The format looks like this:
PS > 02Blue28 Checking xxx service.... at 13:35:43 in 2018
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 beginner in PowerShell. At first, in order to achieve this time real-time display, I used a very stupid method, which is to define a time variable in front of each output statement, which is too tedious, and there must be a simple way to achieve it. Asked the master in the group, and sure enough. PowerShell has a way to define variables directly like this: $(PowerShell-Command).
For example: $(Get-Date)
You can just use it. Here is a complete example: