PoshCode Archive  Artifact Content

Artifact d4afa2a2a4a818fabceef0784bf630f8053b68c9f01b46206aa18660dd1324fb:

  • File Run-Query.ps1 — part of check-in [e6605bffdf] at 2018-06-10 12:56:16 on branch trunk — Runs a FullTextSqlQuery against your local MOSS farm; useful as a quick(!) search query test workbench. (user: unknown size: 1240)

# encoding: ascii
# api: powershell
# title: 
# description: Runs a FullTextSqlQuery against your local MOSS farm; useful as a quick(!) search query test workbench.
# version: 0.1
# type: function
# license: CC0
# function: Run-Query
# x-poshcode-id: 1013
# x-archived: 2009-04-16T01:29:21
#
#
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"