Collect SharePoint Verbose ULS logs for reproducible issues

Summary

If you need to collect VerboseEX logs from a SharePoint Farm, this script makes it simple for reproducible issues. Simply execute the script, reproduce the issue and hit enter …. Done!

What does the script do?

  1. Obtain the current time for the “starttime” parameter in the format that the merge command requires.  
  2. Set the level to VerboseEX
  3. Pause the script while you reproduce the issue.
  4. Determine if a “c:\logs\uls” folder currently exists, if not create one.
  5. The Admin will hit “Enter” to continue after the issue was reproduced.
  6. The script will sleep for 15 seconds to ensure the action if fully completed and written to the logs.
  7. Obtain the current time for the “endtime” parameter in the format that the merge command requires.
  8. Execute Merge-SPLogfile command using our specified start and end times.
  9. Set the logging level back to default.

The Script

Add-PSSnapin Microsoft.Sharepoint.Powershell -ea 0

$StartTime = (Get-Date).ToString()

Set-SPLogLevel -TraceSeverity VerboseEX 

Write-Host "Pausing script!!! Reproduce issue before hitting enter..." -foregroundcolor red -backgroundcolor yellow
Read-Host "Hit enter to end, after the issue is reproduced"


$TARGETDIR = "c:\logs\uls"
if(!(Test-Path -Path c:\logs\uls)){
    New-Item -ItemType directory -Path $TARGETDIR
}


Write-Host Waiting 15 seconds before collecting logs. -foregroundcolor red -backgroundcolor yellow
Start-Sleep 15

$EndTime = (Get-Date).ToString()

Merge-SPLogFile -Path c:\logs\uls\SPLogMerge.log -Overwrite -StartTime $StartTime -EndTime $EndTime 

Clear-SPLogLevel   

Output Example

I hope you found this script useful!

1 Comment


  1. Love it! Simple and effective. Thanks for sharing!

    Reply

Leave a Reply