collecting and merging uls logs

During Troubleshooting and specially working with Microsoft Support team we have to collect logs from all servers in the farm and send it to them.  The issue is that these logs will have more information than what we have with out issue.  So there is the best option.

  1. Create a File
  2. Enable Verbose Ex or Verbose Logging
  3. Reproduce the issue
  4. Disable Verbose Ex or Verbose Logging
  5. Merge the Log Files

Luckily the script below will do that. 

Note: The output file will grow very large in case the issue has multiple steps for repduction + VerboseEx logging produce lot of extra information.  Change the verbose if you are not looking for EX.

save the below script as Ps1 and you are ready.

#Title: ULS Collector
#Description: This script will collect the ULS logs by way of merging them from every server.

#Add SharePoint Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set file location
$path = Read-Host "Please enter the full path for the log file along with the file name";

#Increase logging to verbose
Write-Host "Increasing ULS logging to VerboseEx...";
Set-SPLogLevel -TraceSeverity VerboseEx -EventSeverity Verbose;

#Prompting to start and setting the start time
Read-Host "Hit enter to start, then reproduce the issue"
$starttime = Get-Date -Format "MM/dd/yyyy HH:mm:ss"
Write-Host "The start time for the log file is $starttime";

#Prompting to stop and setting the end time
Read-Host "Hit enter to end"
$endtime = Get-Date -Format "MM/dd/yyyy HH:mm:ss"
Write-Host "The ending time for the log file is $endtime";

#Setting the log level back to normal

#Merging the logs to the specified path using the start and end times
Merge-SPLogFile -Path $path -Overwrite -StartTime $starttime -EndTime $endtime;
Write-Host "Logs have been collected. Resetting the log level back to normal."


One thought on “collecting and merging uls logs

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s