PowerShell default parameters $psdefaultparametervalues combined out-file output to log file _powershell

Source: Internet
Author: User

Output log is an eternal topic, what tracelistener,net4log,nlog,windows with the EventLog, before the automatic redirection PowerShell console output to the file. In fact, with the help of the PowerShell 3.0 powershell default parameter $psdefaultparametervalues, can let out-file, command also become a simple log artifact.

Copy Code code as follows:
$PSDefaultParameterValues [' out-file:filepath '] = ' mylog.txt '
$PSDefaultParameterValues [' out-file:append '] = $true

Set it up, then test it.
Copy Code code as follows:

Ps> ' Log started ' | Out-file
Ps> "time=$ (get-date)" | Out-file
Ps> ' Log ended ' | Out-file
Ps> get-content. \mylog.txt
Log started
time=06/12/2014 11:01:05
Log Ended

article source:http://www.pstips.net/psdefaultparametervalues-2.html

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.