Exchange a PowerShell session login record

Source: Internet
Author: User

you will find it useful to output session records to a log file, for example, to help you save all history commands and to determine if the execution of the automation script is successful. In this section, we'll focus on creating a PowerShell log record.

The steps are as follows:

1. Create a record using the start-transcript command

Start-transcript-path c:\logfile.txt

650) this.width=650; "title=" 01.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M01/59/97/ Wkiom1tyqirjz7bcaac1-epgeye993.jpg "alt=" Wkiom1tyqirjz7bcaac1-epgeye993.jpg "/>

2. After executing several commands

650) this.width=650; "title=" 02.png "style=" height:398px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/97/wkiom1tyqiqq3rwcaaj1v7f1czo512.jpg "width=" 720 "height=" 398 "alt=" Wkiom1tyqiqq3rwcaaj1v7f1czo512.jpg "/>

3. stopping log records

Stop-transcript

4. View the log file and record all the actions we've just made

650) this.width=650; "title=" 03.png "style=" height:429px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m00/59/94/wkiol1tyqx2r75hmaaowaksybzg138.jpg "width=" 720 "height=" 429 "alt=" Wkiol1tyqx2r75hmaaowaksybzg138.jpg "/>

So how does a log record work?

when you turn on PowerShell when logging, you can specify the path and file name of the log file that will be used to record the output of the Run command. Specifying the path is optional, and if you do not specify a path, a file with a random file name will be created under your profile path to see:

650) this.width=650; "title=" 04.png "style=" height:139px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/94/wkiol1tyqx3b9ggqaadrmicjzu8743.jpg "width=" 720 "height=" 139 "alt=" Wkiol1tyqx3b9ggqaadrmicjzu8743.jpg "/>

Record information:

650) this.width=650; "title=" 05.png "style=" height:254px;width:720px; "border=" 0 "hspace=" 0 "src=" http:// S3.51cto.com/wyfs02/m02/59/97/wkiom1tyqiuht21faajqure1gbe891.jpg "width=" 720 "height=" 254 "alt=" Wkiom1tyqiuht21faajqure1gbe891.jpg "/>

when we are done, we can use Stop-transcript command to stop recording, or launch directly PowerShell session. If, of course, the next time you log information, you can use the parameter -append to append the log information to the file where the log information already exists. Of course, you need to specify the file name and path using the-path parameter.

you can record each time the entire session is logged into the log file, so that we need to in the config file if Start-transcript command to the user profile so that the command is called every time the session is started, but keep in mind that we need to specify the path and file name of the log file, and we need to use the -append parameter append log information.

This article from "Robin's Home" blog, declined reprint!

Exchange for PowerShell session logging

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.