Skip to main content
Nintex Community Menu Bar

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. 0System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
  3.  
  4. $file = "logname"
  5.  
  6. $basePath = "C:Logs"
  7.  
  8. $path = $($basePath + """ + $file)
  9.  
  10. $zipPath = $($basePath + """ + $file + ".zip")
  11.  
  12. $startTime = "01/01/1999 00:00"
  13.  
  14. $endTime = "01/01/1999 01:00"
  15.  
  16. $logLibraryName = 'ULS_Logs'
  17.  
  18. New-Item $path -ItemType directory
  19.  
  20. Merge-SPLogFile -Path $($path + """ + "SPLogFile.log") -Overwrite -StartTime $startTime -EndTime $endTime
  21.  
  22. oSystem.IO.Compression.Zipfile]::CreateFromDirectory($path, $zipPath)
  23.  
  24. Remove-Item -Path $path -Recurse
  25.  
  26. $target = $(Get-SPWeb -Identity http://contoso.com).GetFolder($logLibraryName)
  27.  
  28. $stream = $(Get-Item $zipPath).OpenRead()
  29.  
  30. $target.Files.Add($($target.Url + "/") + $($file + ".zip"), $stream, $true)
  31.  
  32. $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).

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)

Reply