cancel
Showing results for 
Search instead for 
Did you mean: 

Gather and upload SharePoint ULS to a Document Library with PowerShell

aaron_labiosa
Nintex Newbie
20 1 730

Products: Nintex Workflow 2013, Nintex Workflow 2010

There is often the need to pull SharePoint ULS logs and share them with another team. Going and manually pulling the logs is often cumbersome and time consuming. This script helps with this by providing a way of pulling the logs, zipping them and uploading them to a SharePoint Document Library.

TIP: This script works very well with the PowerShell action for Nintex Workflow 2013

PowerShell Script
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell
  2. [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
  3. $file = "logname"
  4. $basePath = "C:\Logs"
  5. $path = $($basePath + "\" + $file)
  6. $zipPath = $($basePath + "\" + $file + ".zip")
  7. $startTime = "01/01/1999 00:00"
  8. $endTime = "01/01/1999 01:00"
  9. $logLibraryName = 'ULS_Logs'
  10. New-Item $path -ItemType directory
  11. Merge-SPLogFile -Path $($path + "\" + "SPLogFile.log") -Overwrite -StartTime $startTime -EndTime $endTime
  12. [System.IO.Compression.Zipfile]::CreateFromDirectory($path, $zipPath)
  13. Remove-Item -Path $path -Recurse
  14. $target = $(Get-SPWeb -Identity http://contoso.com).GetFolder($logLibraryName)
  15. $stream = $(Get-Item $zipPath).OpenRead()
  16. $target.Files.Add($($target.Url + "/") + $($file + ".zip"), $stream, $true)
  17. $stream.Close()

To use the script do the following:

  • Ensure you are running the PowerShell console as a SharePoint Administrative account.
  • Configure the URL of the site the ULS logs will be uploaded to (line 26).
  • Configure the StartTime and EndTime of the collection window (lines 12 and 14).
  • Configure the staging path where the log files will be kept prior to uploading (line 6).
  • Configure the destination Document Library for the ULS logs (line 16).
1 Comment
aaron_labiosa
Nintex Newbie

If you run into issues using the above script inside of the NTX PowerShell action, you can substitute lines 26 - 32 with this:

  1. $webclient = New-Object System.Net.WebClient
  2. $webclient.UseDefaultCredentials = $true
  3. $webclient.UploadFile($url, "PUT", $zipPath)