MVPComCamp: PowerShell Automation for Everyone

Last weekend around the world there was a global series of events hosted by Microsoft known as MVPComCamp. I was one of the people to present here in Auckland, New Zealand. I was speaking on a topic dear to me, automation. I’m basically a guy who hates to do boring, repetitive tasks so I like to script as many things as I can.
The aim of my presentation was to show how easy it is to write PowerShell and give everyone the tools that they need to start doing so.

Posted in Conferences, Configuration, Deployment, Development, PowerShell | Leave a comment

Extracting a full list of users from SharePoint

I had an interesting ask from a customer the other day.
“Can I get a report of all the users in the system along with some key pieces of data that is stored on their user profile?”
Sure there are probably a bunch of other ways to do this, search springs to mind. But for this customer the best thing I could give them was a csv file so they could generate some reports and charts from this information. So once again it’s PowerShell to the rescue.

A few things to note about this script, first and foremost the user account executing it MUST have rights to connect to the User Profile Service Application. If they don’t you get a lovely error message which doesn’t make a lot of sense:

New-Object : Exception calling ".ctor" with "1" argument(s): "Object reference not set to an instance of an object."
 + $upa = new-object <<<<  ("Microsoft.Office.Server.UserProfiles.UserProfileManager") $context 
 + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
 + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

If you do have to grant your account permissions to the User Profile Service Application it is necessary to A) restart the service on the server and B) get a fresh PowerShell instance in order for this change to get picked up.This version gets every user profile in your UPA, if you’re after certain people either use .Search() or do some filtering inside the enumeration loop.

Add-PSSnapIn Microsoft.Sharepoint.Powershell
$site = Get-SPSite "http://mysiteurl"
$context = Get-SPServiceContext $site
$upa = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$enumer = $upa.GetEnumerator()
     $user = $enumer.Current
     $row = $user.RecordId.ToString() + ", " + $user.AccountName  + ", " + $user.DisplayName+ ", " + $user["PropertyOfInterest1"]
     write-output $row

According to the docs for IEnumerator on MSDN MoveNext() will return false when it moves beoynd the bounds of the collection being enumerated and Reset() followed by MoveNext() should be used to set the Current item to the first item in the collection.I’ve used Write-Output in this case because I can easily combine this with Output-File to create csv output files like so:

.\ReadUsers.ps1 | Output-File .\UserDump.csv
Posted in PowerShell, SharePoint | Tagged , , | Leave a comment

The Sandbox is dead! Long live the Sandbox!

So, you may have heard that Sandboxed solutions have be deprecated in SharePoint 2013. This was one of the big news items that came with the new version of the product along with the new SharePoint App Model.

That’s not entirely correct.

User code is deprecated. What does that mean for us as developers?

Simply that we can safely continue to use sandboxed solutions to deliver declarative customisations to our SharePoint site collections. Things like Web Templates, Content Types, Custom List definitions etc., are all still supported and will still be so for vNext.

I’m really happy that this clarification has been made, and confirmed by another source inside Microsoft. This makes the future of delivering customisations to SharePoint Online and at a Site Collection level much clearer.

Posted in Uncategorized | Leave a comment

Name ActiveX controls for public sites AKA go away name.dll prompt

So, I use Chrome, there I said it. They say that admitting you have a problem is the first step to solving it. Anyway when I’m browsing the web using what is, in general, a pretty good browser I’ll every so often see this:

Don't show this on the internet, this is a horrible thing for the public!

As an anonymous user I don’t want to, nor should I ever see this.

So, what’s happening here?

SharePoint really has its roots as an internal collaboration tool and one of the really great things it does in this space is show presence indicators for other users. Now, those online presence indicators and the contact cards they spawn which let you initiate an IM or Lync call, they use an ActiveX control for this whiz-bang functionality.

Luckily there is an simple way of disabling this functionality. For 2010 and 2013 you can disable the presence indicators on a per-web application basis:


But the downside here is pretty obvious, it’s for the whole web app, and if you’re using Host Named Site Collections that’s going to hit a few more sites than the public facing one you’re trying to prevent that ugly prompt on.

Luckily there is another approach, with a couple of lines of JavaScript embedded into the master page this problem can be switched off:

<!--<SharePoint:SPSecurityTrimmedControl runat="server" AuthenticationRestrictions="AnonymousUsersOnly" >-->
  <script type="text/javascript">
    function ProcessImn() { }
    function ProcessImnMarkers() { }

Kudos goes to Randy Drisgill for this wee gem which I got switched onto when using the SharePoint 2010 Starter Master Pages. Be aware that it’s not in the 2013 Starter Master Pages as yet.

Now, you’ll note the SPSecurityTrimmedControl in there, that is to ensure that fragment is only ever present in the HTML for anonymous users. So authenticated users can see presence indicators and easily chat with colleagues working on the site too.

Those comment tags?

Well the SPSecurityTrimmedControl emits either a <span> or a <div> tag which is a no-no in the <head> of your HTML, the comment tags there just stop the browser interpreting the erroneous tags and deciding that the <head> should stop there.

Posted in Development, SharePoint | 3 Comments

SPDisposeCheck: Do not use for SharePoint 2013

I like many SharePoint developers out there I am user of SPDisposeCheck. My team and I use this as in our Continuous Integration builds as one of our quality checks on to determine if our code is passing the checks we need for a ‘green’ build.

In fact SPDisposeCheck is so valuable in terms of catching issues before they get into any live code from my team I consider it to be, borrowing from Doug Ware’s metaphor, the safety catch on my machine gun.

During beta we discovered that SPDisposeCheck was not working for SharePoint 2013.

Consider this code:

This code leaks like a seive

Now most of you who have done a bit of SharePoint development should be able to see that code has a gaping memory leak and should not pass SPDisposeCheck.

SPDisposeCheck zero issues found

Yeah, that’s not ideal…

But what about static code analysis? Microsoft.Reliability: CA2000 Dispose objects before losing scope is supposed to catch things like this too, right? Unfortunately this memory leak slips right past that check too.

Code analysis no issues found

This still has not been resolved. Yes, if you were doing SharePoint 2013 and thinking that you’re doing the right thing, using SPDisposeCheck, you need to do a code review. Now.

Myself and other SharePoint MVPs who are development focused are doing our best to keep this on the radar within Microsoft.

I for one really hope that we do get another version of SPDisposeCheck that can analyse our .NET 4.5 SharePoint 2013 code to stop developers out there from shoot themselves in the foot and taking down SharePoint servers with memory leaks.

Posted in Best Practice, Development, SharePoint | 4 Comments

Practical Guide to Public Facing sites

This year I presented a second session at the New Zealand  SharePoint Conferences, on “A Practical Guide to Public Facing web sites”. As promised in my session here is the slide deck.

Posted in Conferences, Development, SharePoint | Leave a comment

Writing testable SharePoint code: New Zealand and Australian SharePoint Conferences

This year I was lucky enough to be invited back to present at the New Zealand and Australian SharePoint Conferences, this time on “Writing Testable SharePoint Code”. As promised in my sessions here is the slide deck and, more importantly, the sample code :)

Posted in Conferences, Development, SharePoint, Visual Studio | Leave a comment