Creating log files in Powershell scripts


I was working on a project in which I had to create a script to do some solution deployment, site creations etc., and while doing these the script shoul create log file to log entire process. This is a sample script which i worked out and could be useful to all needy.

This script has 3 functions those will be taking care of generating log files.

  1. LogInfo: General information will be logged, it is called as and when a normal process is completed.
  2. LogError: Errors will be logged, it is called when an error is encountered.
  3. ConfigureLogger : This function is for configuring Log:
    1. The directory where the logs will be stored
    2. Name of the log file
    3. Pattern of writing the log file

In this script i have taken SharePoint Admin & Timer service for example, the script will start these two service if they are not and log the same in log file.

I have attached the script, please change the extension of the file prior executing.

LogFileInPS.PS1.txt

Comments (0)

Skip to main content