Check for Group existence in SharePoint Site

In SharePoint 2013 server side object model (SSOM), it appears that the Method overloads of the SPGroupCollection such as GetByName() or indexer all throw an exception when the group is not found.  However, you can still use reflection to get non throwing version of the methods. In my project I ended up creating an extension method that wraps the reflection based function call.

public static class SPGroupCollectionExtensions
{
  public static SPGroup GetByNameNoThrow(this SPGroupCollection group, string groupName)
  {
    var method = group.GetType().GetMethod("GetByNameNoThrow", BindingFlags.Instance | BindingFlags.NonPublic);
var parameters = new object[] {groupName};
    return (SPGroup)method.Invoke(group, parameters);
   }
}
Advertisements

User Profile Synchronization Service won’t start due to PowerShell profile

Recently, I had been asked by the colleague to help them troubleshoot the issue where User Profile Synchronization service would hang during the attempt start.

There were no error logs except that it would return to Stopped state. We found out that if the account that you login is the same account that you run the User Profile Synchornization Service and that account has a powershell profile, then it causes the issue. It appears that during the start process of the UPS Synch service, it runs the PowerShell runspace with the default shell as opposed to creating its custom shell, so default profiles in your documents folder would be loaded. Thus, the issue.

Best way to resolve is to ensure that even in your dev environment, you must make sure that you’re not running your interactive shell with the account that’s running SharePoint services processes.

View SharePoint Deployment Progress

In the past, I have blogged that when a developer deploys the a WSP package through PowerShell, it’s nice to see if the deployment job succeeds before moving on to the next step.

In the past, this is the command I have used:

Get-SPSolution -Identity SomeSolution.wsp | Select Last* | fl

And waited until all servers in the farm are reporting that deployment is successful.  However, at times the job is still running.  A more robust approach I use now is to look for JobExists property and ensure that it’s false.  Therefore updated command I use now:

Get-SPSolution -Identity SomeSolution.wsp | Select Last*, JobExists | fl

Deleting TFS Work Item

I was creating a number of user stories and associating the Tasks to users, and quickly realized that the TFS 2013 still does not have a way to delete a task.  Woooaahhh!!!

There is a way to do it via command line, via witadmin tool:

witadmin destroywi /Collection:<TFS Collection URL> /id:<id of the task>

Managing Azure dev environment from PowerShell

Recently, I’ve been spending some time prototyping the new SharePoint 2013 App Model in my Azure provision SP2013 development environment.  I wanted to make sure that i can shut it down or start it up quickly.  So PowerShell is of course the answer here.

Small assumption is that the Azure Service Name matches the Virtual Machines. It is possible to have multiple virtual machines provisioned under the same service Name

First, ensure that the valid Azure subscription is attached to the Azure command line session:

Get-AzureAccount

If that returns no subscriptions, then use Add-AzureAccount commandlet to add an active subscription.
To start/stop the Azure Virtual Machines I use these commands:

Get-AzureVM -ServiceName <ServiceName> | Start-AzureVM
Get-AzureVM -ServiceName <ServiceName> | Stop-AzureVM -Force:$true

I’ll add more commands as i start doing more complex things with Azure dev boxes as I go along.

Design Manager woes with plain HTML

In our recent projects for SharePoint 2013, we have to use the design manager to build a responsive branding design package.  If you are not familiar with this new feature, please take a look at  Overview of Design Manager in SharePoint 2013 to familiarize yourselves.

One of the challenges that we found with SharePoint 2013 Design Manager is that it modifies and rearranges not only <!–MS/ME/SPM –> markup code, but also the HTML itself during design package import process.

One such example was when we included protocol agnostic script source tag for jquery.


<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

The resultant tag in the imported instance was the following.


<script type="text/javascript" src="/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

After attempting various tricks using <!– –> markup and trying to enclose the html in the design manager tags with no particular success.  The workaround was as follows, after obtaining an answer to our post on MSDN forum:


<!--SPM:<asp:Literal runat="server" Text="&amp;#60;script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js' &amp;#62; &amp;#60;/script&amp;#62;" /> -->

The Literal ASP.Net server control is used to emit raw html that we need during response. Note, that the input has to be html encoded to avoid further issues with Design Manager.  This is really ugly but will do for now.