Generate Multiple Views on SharePoint Lists or Libraries

I was having a weird problem with a list we had migrated, and one of the unusal characteristics was that this list had about 50 different views.

To try and replicate the issue with another list, I wanted to create 50 views very quickly.

Here is how I did it in PowerShell:

$w = Get-SPWeb http://portal.company.com
$l = $w.Lists["Documents"]
$maxViews = 50
 
for ($viewCount=0;$viewCount -lt $maxViews;$viewCount++)
{
	# $null prevents flooding the screen with view information
	# Clone Method Parameters: Name, Row Limit, Paged, Make Default View
	$null = $primaryView.Clone(($primaryView.Title + " " + $viewCount) , 30, $true, $flase)
}

The script worked like a charm in creating the views, however didn’t help me resolve the issue I had with my list.

Disable SharePoint Mobile View with PowerShell

A client recently had a request to disable the mobile view feature of SharePoint 2010. Fortunately, Jeremy Thake has written an excellent article on this already – How We Did It – Mobile View. We tested the second option and decided to go with that approach. The only problem was that I wasn’t keen on editing 10 web.config files.

Again, PowerShell comes to the rescue! I discovered that we could make web.config changes with the SharePoint object model, and therefore have all configurations updated at once. Special thanks to Farhan Faiz for his blog entry: SharePoint 2010: PowerShell script to add in web.config.

$webApp = Get-SPWebApplication http://portal.company.com
$configMod = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$configMod.Path = "configuration/system.web"
$configMod.Name = "browserCaps"
$configMod.Sequence = 0
$configMod.Type = 0
$configMod.Value = "<browserCaps> </browserCaps>"
 
$configMod1 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification
$configMod1.Path = "configuration/system.web/browserCaps"
$configMod1.Name = "result"
$configMod1.Sequence = 0
$configMod1.Type = 0
$configMod1.Value = "<result type=""System.Web.Mobile.MobileCapabilities, System.Web.Mobile, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a""/><filter>isMobileDevice=false</filter>"
 
$webApp.WebConfigModifications.Add($configMod)
$webApp.WebConfigModifications.Add($configMod1)
$webapp.Update()
$webapp.Parent.ApplyWebConfigModifications()
$webapp.WebConfigModifications.Clear()

Broken Profile Pictures in My Site

I was presented with an interesting issue this week, when internally we were set to roll out My Sites across the organisation.  The only problem was, all the profile pictures were not displaying correctly on our profile pages.

image

The first thing to check was if the pictures existed correctly in the User Photos library (http://mysite.company.com/User%20Photos) and sure enough they were there.

image

When viewing the properties LThumb version, it was displaying correctly,

image

Interestingly, the URL on the properties of the image as:
http://mysite.company.com/User%20Photos/Profile%20Pictures/_w/DOMAIN_pheydon_LThumb_jpg.jpg

Notice the “_w” – this appears to be a preview image, and not the image itself.  So back to the User Photos library to find the correct URL of the LThumb photo to be:

http://mysite.company.com/User%20Photos/Profile%20Pictures/DOMAIN_pheydon_LThumb.jpg

And when accessed in Internet Explorer, it renders as a broken image.

image

What is even more interesting is that the photo with the same URL works fine in Firefox (as well as Chrome and Safari)

image

A further test of the MThumb and SThumb versions of the photo render correctly in Internet Explorer.  At this point SharePoint is ruled out as being the issue, and it appears that Internet Explorer is having a problem with the pictures.

The next check is to compare the differences between the broken and working pictures.  A close examination of the original, LThumb (left) and MThumb (right) show the difference in the bit depth.

image

After opening and resaving the file locally on the file system, the file opened correctly in Internet Explorer.  These pictures were originating from Active Directory, and after a bit of digging around, we discovered that the guys uploading these pictures into AD had put them in as a GIF format with a reduced bit depth for getting them below 10KB in size (required for inserting the images into AD).  They had also saved them as a JPG before uploading them.

Strangely enough, Outlook and Lync were displaying these pictures without a problem.  What is even stranger is that the process SharePoint uses to create the medium and small thumbnails seems to have no problem either.  The Large version is clearly just a copy of whatever is being held in AD.

A colleague pointed out that it was probably a security feature of Internet Explorer that it detected that the file extension (JPG) was different to the header information in the file (GIF) and thus refusing to display it. 

This makes perfect sense, and once explained to the AD guys, they are  now busy re-converting everyone’s photos to the correct format.

Another case of “Cannot Run SharePoint 2010 PowerShell Cmdlets”

For anyone trying to run SharePoint 2010 PowerShell Cmdlets, this message typically comes up at some stage:
“The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.”

The most common cause is insufficent permissions to the SharePoint’s Config Database. (Specifically the person logged in needs the role SharePoint_Shell_Access to this DB).  Sometimes the Management Shell needs to also be ran as administrator for it to work properly too.

Today I came across a scenario with a customer whereby we had set them up with the correct access to the Config DB, but a couple of days later it stopped working, with the abovementioned bolded error.

It turns out that they had setup SQL with high-availability mirroring, and that their mirror had failed over to the secondary host.  Te user trying to run PowerShell cmdlets was not setup with permissions on this server.  Giving them permissions on the secondary SQL server allowed them to run the SharePoint PowerShell cmdlets successfully.

Finding User Profiles With A Specific Property

Today I was looking at a user profile property in SharePoint 2010, and wondered why the usage (ie “number of profiles using this property”) was relatively low. I needed a quick way to get this information out.

The first two lines should be modified to your MySites host and the property you want to audit (eg PictureURL). The last line is an object representing the value of each property where populated and can be easily modified to suit your query.

$mySiteUrl = "http://mysites.company.com"
$findProperty = "PictureUrl"
 
$mySiteHostSite = Get-SPSite $mySiteUrl
$mySiteHostWeb = $mySiteHostSite.OpenWeb()
$context = Get-SPServiceContext $mySiteHostSite
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$AllProfiles = $profileManager.GetEnumerator()
$outputCollection = @()
 
foreach ($profile in $AllProfiles)
{
    $output = New-Object System.Object
    $output | Add-Member -type NoteProperty -Name AccountName -Value $profile["AccountName"].ToString()
    $output | Add-Member -type NoteProperty -Name $findProperty -Value $profile[$findProperty] 
    $outputCollection += $output
}
 
$outputCollection | ? {$_.($findProperty) -ne ""} | Sort-Object -Property AccountName