Long live the best SharePoint ULS Viewer

Update (15th June 2014): We may see a return of the SharePoint ULS Viewer very soon. Jeremy Thake and Office Dev indicated it is coming back to life very soon.

Community Discussion (9th June 2014): SharePoint Consultant and MVP Vlad Catrinescu has started a discussion about possible replacements for the ULS Viewer on the SharePoint Community site (http://sharepoint-community.net/forum/topics/what-is-the-best-replacement-for-ulsviewer).

After noticing a tweet from Brian Lalancette ‏(@brianlala, you might also know him through his AutoSPInstaller project), I gasped at the thought that the best ULS Viewer for SharePoint is no longer going to be available.

Along with many others in the SharePoint community I was quite surprised by this news and started to consider what alternative were available. I’ve used the ULS Viewer from MSDN so many times I have lost count and don’t know where I would be without it.

The best ULS Viewer
The best ULS Viewer

For those who’ve found this post and just want to download a copy of the ULS Viewer tool you’re in luck. I have preserved a copy of ULS Viewer as a .exe and a .zip archive – these are available here http://bit.ly/UlsViewer and http://bit.ly/UlsViewerzip.
You might receive a warning from the URL shortening service when using the .exe link warning against directly downloading an exe – this is why I have also provided a ZIP version.

Other SharePoint ULS Viewer tools…

As the ULS Viewer is no longer available I thought I shared some alternative tools or techniques to get access to the SharePoint ULS logs.

ULS Studio

A Codeplex project that I’ve used on several occasions and does somewhat come close to the features that the ULS Viewer tool had – ULS Studio (https://uls.codeplex.com).

ULS Studio
ULS Studio

CSOM for SharePoint Online

If you’re using SharePoint Online you could follow Vardhaman Deshpande’s blog post (http://www.vrdmn.com/2014/03/view-tenant-uls-logs-in-sharepoint.html) and access the ULS logs using the Client-Side Object Model (CSOM).

SPO ULS with CSOM - Vardhaman Deshpande
SPO ULS with CSOM – Vardhaman Deshpande

Developer Dashboard

There’s also the ULS tab within the Developer Dashboard, although this is limited to reviewing errors related to those requests where the Developer Dashboard is displayed or used.

The Developer Dashboard can be activated using PowerShell – SharePoint Developer Devendra Velegandla shares the PowerShell and reviews the Developer dashboard on his blog (http://www.sharepoint-journey.com/developer-dashboard-in-sharepoint-2013.html).

[code language=”PowerShell”]
$svc = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$dds = $svc.DeveloperDashboardSettings
$dds.DisplayLevel = "On"
$dds.Update()
[/code]

ULS errors displayed in the Developer Dashboard
ULS errors displayed in the Developer Dashboard

PowerShell

Use can even use PowerShell to get details about a correlation error. Wictor Wilén shares details about this method in an article on his blog (http://www.wictorwilen.se/Post/Working-with-SharePoint-2010-Correlation-ID-in-PowerShell-and-code.aspx).

[code language=”PowerShell”]Get-SPLogEvent | out-gridview[/code]

Get-SPLogEvent | Out-GridView
Get-SPLogEvent | Out-GridView

Summary

While I’m not going to stop using the ULS Viewer – I can only recommend you use something to help you view the SharePoint ULS logs. Troubleshooting SharePoint is not easy but you can help yourself, firstly by always checking the event log and secondly being comfortable with your method of doing.

Long live the best ULS Viewer.

Working with SharePoint’s Second Stage Recycle Bin in PowerShell

I thought I’d share a PowerShell script that I’ve created to perform a few tasks against a Site Collection Second Stage Recycle Bin (SSRB) in SharePoint.

Remove-SecondStageRecycleBinItems.ps1
Remove-SecondStageRecycleBinItems.ps1

The requirement was to delete items that were older than a set number of days from the Second Stage Recycle Bin (SSRB). A record of each item deleted also needed to be added to a report.  But SharePoint can do this already I hear you say…well yes if a Site Collection quotas and the auditing features are used. In this scenario neither could be.

To display items in the Second State Recycle Bin in a table I used this command.

[code lang=”powershell”]$site.Recyclebin | where { $_.ItemState -eq "SecondStageRecycleBin" -and $_.deleteddate -le $dateDiff} | Format-Table -Property Title, Web, DeletedBy, DeletedDate -Autosize -Wrap
[/code]

Then to remove each item from the Recycle Bin I used the delete command.

[code lang=”powershell”]$site.Recyclebin.Delete($_.ID)[/code]

The full script is shared below. Remember to review, rename and test this script before using it in a production environment.

[code lang=”powershell”]
#——————————————————————————–
#
# Remove-SecondStateRecycleBinItems.ps1
#
# Author: James Callaghan (www.jcallaghan.com)
# Date: April 2014
#
# This script will delete items from the Second Stage Recycle Bin that
# are older than XX days.
#
#——————————————————————————–

Add-PSSnapin Microsoft.SharePoint.PowerShell

#Variables
$i = 0

#SharePoint Site Collection URL
$url = "http://apm.dev.jcallaghan.com"
#$url = Read-Host "Enter a valid URL to a SharePoint Site Collection?"
#if($url -eq ""){write-host "No URL provided." -foregroundcolor Red; Exit}

#How many days ago should items be deleted from?
$deleteFrom = -10
#$deleteFrom = Read-Host "Remove items older than how many days?"
#if($deleteFrom -eq ""){write-host "No value provided." -foregroundcolor Red; Exit}

#Create report in script path
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$report = "$($dir)\DeletedSecondStateRecycleBinItems.csv"

#Date calculations
$dateNow = Get-Date
$dateDiff = $dateNow.AddMinutes(-$deleteFrom)
#$dateDiff = $dateNow.AddDays($deleteFrom)

#Display date/times for review in table
$table = @()
$review = New-Object System.Object
$review | Add-Member -type NoteProperty -Name "Date" -Value "Timestamp now"
$review | Add-Member -type NoteProperty -Name "Value" -Value $dateNow
$table += $review
$review = New-Object System.Object
$review | Add-Member -type NoteProperty -Name "Date" -Value "Files older than"
$review | Add-Member -type NoteProperty -Name "Value" -Value $dateDiff
$table += $review
$table | Format-Table –AutoSize

#Connect to the site
$site = Get-SPsite $url

#Report file and first row
New-Item $report -type file -Force | Out-Null
Add-Content $report "Deleted Items: $($dateNow)"
Add-Content $report "Name, Title, Deleted by, Deleted date, Path, File Guid"

#Get items from the Seconday Stage Recycle Bin (SSRB) that are older than are removel period.
$items = $site.Recyclebin | where { $_.ItemState -eq "SecondStageRecycleBin" -and $_.deleteddate -le $dateDiff}
$site.Recyclebin | where { $_.ItemState -eq "SecondStageRecycleBin" -and $_.deleteddate -le $dateDiff} | Format-Table -Property Title, Web, DeletedBy, DeletedDate -Autosize -Wrap

#Confirm there are items to delete
if($items -ne $null){

#Create prompt
$ok = New-Object System.Management.Automation.Host.ChoiceDescription "&OK","Description."
$cancel = New-Object System.Management.Automation.Host.ChoiceDescription "&CANCEL","Description."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($ok, $cancel)
$title = "Confirm"; $message = "Delete items from Second Stage Recycle Bin?"
$result = $host.ui.PromptForChoice($title, $message, $options, 1)

switch ($result) {
0{
#Get items to be deleted
$site.Recyclebin | where { $_.ItemState -eq "SecondStageRecycleBin" -and $_.deleteddate -le $dateDiff} | foreach{
#Add entry to report
Add-Content $report "$($_.LeafName),$($_.Title),$($_.deletedbyname),$($_.deleteddate),$($_.Dirname),$($_.Id)"

#Delete item by ID
$site.Recyclebin.Delete($_.ID)

$i++
}
write-host "$($i) items removed from Second Stage Recycle Bin."
}1{
write-host "Cancelled by user." -foregroundcolor Red
}
}
}else{
write-host "No files were found in the Second Stage Recycle Bin." -foregroundcolor Red
}

#Dispose
$site.dispose();
[/code]

One quirk I found while creating the script was that through the web browser, SharePoint reported the time each file was deleted correctly whereas in PowerShell, the time was not honouring GMT summer time.

British Summer Time  in SharePoint vs. PowerShell
British Summer Time in SharePoint vs. PowerShell

Enjoy and delete carefully!

Configuring a host name with a SSL Certificates in IIS 7

A customer asked me if I could help troubleshoot their SharePoint environment – they had extended a web application and configured it to use Forms Based Authentication (FBA) with SSL however they were getting errors when accessing the new site.

I started troubleshooting the configuration across all the servers in their SharePoint 2013 farm. I stepped through the configuration for the web application in Central Administration – reviewing the authentication provider settings and alternate access mappings. I then reviewed the web.config and made sure that the FBA settings were present and correct along with the IIS website bindings. This is when I noticed that there was no host name against the https/443 binding –  the option to add one was also disabled.

IIS binding - host name disabled
IIS binding – host name disabled

After a little research I found an article from ArmgaSys.  It turns out that my customers wildcard SSL certificate was issued without a * in the name therefore the host name cannot be specified once the SSL certificate is selected. I followed the steps in this article from and the customer was able to access their SharePoint site without any errors this time.

IIS binding - host name editable
IIS binding – host name editable

A summary of these instructions are included below: –

  1. To resolve this and make the host name field editable launch Microsoft Management Console (MMC) and open the Certificates snap-in.
  2. Locate the wildcard certificate, right click on it and select properties.
  3. If the Friend Name property doesn’t start with a * then add one and apply any changes you make.
  4. Now go back to IIS and select the SSL certificate in the bindings of the SharePoint website with the issue.
  5. The host name field should now be editable where you should then enter the host name for your SharePoint site.

Change the default sync interval – Windows Azure Active Directory Sync

The default interval for Windows Azure Active Directory Sync (DirSync) synchronisations is 3 hours. If for instance your Active Directory has lots of changes you you’ll probably want to consider shortening the sync interval.

The schedule can be modified by changing the “Microsoft.Online.DirSync.Scheduler.exe.Config” configuration file. Before proceeding to make any changes to the sync interval you should evaluate how long it takes to complete a synchronisation. You can do this by reviewing the application event log for entires that indicate when a sync has started and completed.

To modify the configuration file open “C:\Program Files\Windows Azure Active Directory Sync\Microsoft.Online.DirSync.Scheduler.exe.Config” in Notepad. You will then need to modify value of the “Synctimeinterval” key – the notation of this is Hours:Minutes:Seconds.

Microsoft.Online.DirSync.Scheduler.exe.Config
Microsoft.Online.DirSync.Scheduler.exe.Config

Save the configuration file and restart the “Windows Azure Active Directory Sync Service” Windows Service (via PowerShell Restart-Service MSOnlineSyncScheduler) to apply this change.

Restart-Service MSOnlineSyncScheduler
Restart-Service MSOnlineSyncScheduler