Spdiagnosticssession, merge-sploG AND ulSVIEWER

If you facing an issue in SharePoint environment and you are trying to get the ULS logs you can use the below method to get the log efficiently.  Althought the process can be done from UI but it takes more effort.

# Use the Start-SPDiagnosticsSession cmdlet to report diagnostic information to the usage database. # After a diagnostic session starts, all Windows PowerShell for SharePoint cmdlets in Windows PowerShell scripts # will use the same correlation to report diagnostic information.

$correlationId = [guid]::NewGuid() Start-SPDiagnosticsSession -CorrelationId $correlationId -Dashboard:$true -TraceLevel Verbose

Now you can reproduce your scanario or error so that the logs are generated.  Now you can close the Diagnostic sessions.

#Run the below Line Stop the Diagnostic Session
Get-Content e:\data\SharePoint\Logs\*.log | select-string $correlationId | clip
Get-Content e:\data\SharePoint\Logs\*.log | select-string $correlationId | Diag.txt 

#Get-Content *.log | select-string $correlationId
Get-Content e:\data\SharePoint\Logs\*.log | select-string $correlationId 

You can also use Merge-SPlogFile to collect the logs into a single file.

Merge-SPLogFile -Correlation $correlationId -Path "E:\Data\MergedLogs\MergeedLog.log" -Overwrite

Now you can open ULS Viewer directly for this file.


.\ulsviewer.exe -filename E:\Data\MergedLogs\MergeedLog.log


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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