Get SearchServiceApplication in PowerShell

In C# when retrieving the default SearchServiceApplication object you might do something like the following, if you were trying to initiate a new Schema object, for example:

SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
 
SearchServiceApplicationProxy searchApplicationProxy = serviceContext.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy;
 
Guid applicationId = searchApplicationProxy.GetSearchServiceApplicationInfo().SearchServiceApplicationId;
 
SearchServiceApplication searchApplication = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(applicationId);
 
Schema schema = new Schema(searchApplication);

If you’re looking to implement something similar in PowerShell, you don’t have to write quite as much code. Take a look at the following script, which achieves the same goal:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
 
$searchApplication = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
 
$schema = New-Object Microsoft.Office.Server.Search.Administration.Schema($searchApplication);

The call to Get-SPEnterpriseSearchServiceApplication is all that’s required to retrieve the default SearchServiceApplication object.

Simples!

Posted in SharePoint | Tagged , , | Leave a comment

Field Order for External Content Type

Working with external content types isn’t as straight forward as it should be, especially within a Visual Studio project. Take trying to define the display order of your columns as an example.

You define your task entity by adding your required Type Descriptors in BDC Explorer. The order the columns will display in external views is dependant on the order they are listed in the BDC Explorer. That’s all well and good but there’s no way through the UI to change this order.

The easiest way to change the order is to directly edit the dbcm file in your favourite text editor, mine is Notepad++. Other text editors are available 🙂

In Visual Studio, right click your model in the Solution Explorer pane and click Open Folder in File Explorer. In the folder that loads, open the bdcm file in your editor of choice.
Continue reading

Posted in SharePoint | Tagged , , , | Leave a comment

Show Web Template

Carrying on from my previous post Hide Web Template, this post demonstrates how to show a web template in the New Site dialog for a specific web using a PowerShell script:

function Add-SPWebTemplate {
	[CmdletBinding()]
	param(
		[parameter(Position=1,Mandatory=$true)][Microsoft.SharePoint.SPWeb]$web
	)
	process {
		$templates = New-Object "System.Collections.ObjectModel.Collection``1[[Microsoft.SharePoint.SPWebTemplate, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c]]"
		$availableWebTemplates = $web.GetAvailableWebTemplates(1033);
 
		$availableWebTemplates | ForEach-Object {
			if ($_.ID -eq 53) {
				Write-Host ("Blank Internet web template is already enabled for web '", $_.Title, "' at ", $_.Url -join "") -NoNewline
				return
			}
 
			$templates.add($_)
		}
 
		$web.AllowAllWebTemplates()
		$allWebTemplates = $web.GetAvailableWebTemplates(1033);
 
		$allWebTemplates | Where{ $_.ID -eq 53 } | ForEach-Object {
			$templates.add($_)
		}
 
		Write-Host ("Enabling Blank Internet web template for web '", $_.Title, "' at ", $_.Url -join "") -NoNewline
		$web.SetAvailableWebTemplates($templates, 1033);
		$web.Update()
		Write-Host " - Done." -ForegroundColor Green
	}
}
 
 
Get-SPWebApplication | ForEach-Object {
	$_.Sites | Where { $_.ServerRelativeUrl -ne '/sites/example' } | ForEach-Object {
		$_.AllWebs | ForEach-Object {
			Add-SPWebTemplate $_
		}
	}
}

Continue reading

Posted in SharePoint | Tagged , | Leave a comment

Debugging InfoPath Browser Form

If you’re using custom code with your browser enabled InfoPath forms and would like to be able to debug them, follow the steps outlined below to configure the form to enable this.

Open the Visual Studio Tool for Applications(VSTA) editor with the code behind for your InfoPath form. In the solution explorer pane, right click your project and select Properties.

Switch to the Build tab and click the Advanced button:

Advanced Button
Continue reading

Posted in InfoPath, SharePoint | Tagged , | Leave a comment