Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.2 KB

File metadata and controls

50 lines (37 loc) · 1.2 KB
pid 1013
author Peter
title
date 2009-04-09 01:48:11 -0700
format posh
parent 0

Runs a FullTextSqlQuery against your local MOSS farm; useful as a quick(!) search query test workbench.

function Run-Query($siteUrl, $queryText)
{
	[reflection.assembly]::loadwithpartialname("microsoft.sharePOint") | out-null
	[reflection.assembly]::loadwithpartialname("microsoft.office.server") | out-null
	[reflection.assembly]::loadwithpartialname("microsoft.office.server.search") | out-null
	$s = [microsoft.sharepoint.spsite]$siteUrl
	$q = new-object microsoft.office.server.search.query.fulltextsqlquery -arg $s
	$q.querytext = $queryText
	$q.RowLimit = 100
	$q.ResultTypes = "RelevantResults"
	$dt = $q.Execute()
	$r = $dt["RelevantResults"]

	$output = @()
	
	while ($r.Read()) {
		$o = new-object PSObject

		0..($r.FieldCount-1) | foreach {
			add-member -inputObject $o -memberType "NoteProperty" -name $r.GetName($_) -value $r[$_].ToString()
		}
		
		
		$output += $o
	}
	
	return $output
}

@@#Sample usage:
@@#Run-Query -siteUrl "http://dev/" -queryText "SELECT PreferredName, WorkPhone FROM S"