-1

I just started using power shell and the first assignment wants us to log everything we do into a log file.

The way that the lab is telling us to do it is as follows:

"Create a file by executing the following command: date >> LAB-winsrv.log"

"Do an ipconfig to show all interfaces and output the results to the logfile"

"Use ipconfig to bring back up the interface you shut down above and output the results of that command to the logfile"

So basically, it will ask you to perform a quite simple task and then have the resulting output added to the log file that was created. However, I am having trouble figuring out exactly how to do that.

Gohawks
  • 21
  • 4
  • Possible duplicate of [Write output to a text file in PowerShell](https://stackoverflow.com/questions/18469104/write-output-to-a-text-file-in-powershell) – Daniel Mann Apr 20 '19 at 16:33

2 Answers2

0

The simplest way to create the log file is by reading the directions you provided: "Create a file by executing the following command: date >> LAB-winsrv.log"

The >> will create the file. I'd suggest telling it where to save the log file too, so you can find it later...

date >> C:\Temp\LAB-winsrv.log
DBADon
  • 449
  • 5
  • 9
0

Powershell transcription is a feature where all output to the console is written to a file. By default it is already enabled but if you want to control the location you can start it explicitly withstart-transcript and specify the log file as well. You can naturally stop it with stop-transcript.

The output both to the console and by extension to the transcript file can be enhanced by use of my XWrite. More information with some examples available on the GitHub repository.

Alex Sarafian
  • 634
  • 6
  • 17