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?
- Obtain the current time for the “starttime” parameter in the format that the merge command requires.
- Set the level to VerboseEX
- Pause the script while you reproduce the issue.
- Determine if a “c:\logs\uls” folder currently exists, if not create one.
- The Admin will hit “Enter” to continue after the issue was reproduced.
- The script will sleep for 15 seconds to ensure the action if fully completed and written to the logs.
- Obtain the current time for the “endtime” parameter in the format that the merge command requires.
- Execute Merge-SPLogfile command using our specified start and end times.
- 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!
Permalink
Love it! Simple and effective. Thanks for sharing!