Get the App
SLTechnology News&Howtos  ›  Servers  › 

PowerShell-output the execution result like Log

Shulou Source: shulou.com Published: 2022-06-02 17:25:10 09月22日 Update

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:

Tags: Real-time methods results output variables time tedious examples beginners that is console daily work clarity format statement software master work control affirmation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei NVidia macOS Microsoft