Pages

Tuesday 20 November 2012

How to log the output to a text file for a powershell script

Problem

Some times when performing bulk operations you would want to log the output of a powershell script to a text file, so you can examine the results and perhaps even investigate what went wrong.

Solution:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\Admin\SiteFeaturesoutput.txt -append


.
.
Your script goes here
.
.
Stop-Transcript

No comments:

Post a Comment