Skip to content

Instantly share code, notes, and snippets.

@rheid
Created May 4, 2014 17:11
Show Gist options
  • Save rheid/2ce55b40971f122d1ceb to your computer and use it in GitHub Desktop.
Save rheid/2ce55b40971f122d1ceb to your computer and use it in GitHub Desktop.
Param(
[string] $url = $(Read-Host -prompt "Enter Site Collection URL: ")
)
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PsSnapin Microsoft.SharePoint.PowerShell
}
Write-Host " "
Write-Host " Script provided by Summit 7 Systems for information/educational purposes only. Use at your own risk."
Write-Host " http://s7sys.biz/restsearch http://www.Summit7Systems.com"
Write-Host " "
$farmID=(Get-SPFarm).Id
$spSite=Get-SPSite $url
$siteColId=$spSite.Id
$topLevelSiteID=$spSite.RootWeb.Id
$rootWeb=$spSite.RootWeb
if($null -ne $rootWeb)
{
$list=$rootWeb.Lists["QueryPropertiesTemplate"]
if($null -eq $list)
{
$template=$rootWeb.ListTemplates["Document Library"]
$list=$rootWeb.Lists[$rootWeb.Lists.Add("QueryPropertiesTemplate","QueryPropertiesTemplate",$template)]
}
$scriptFile = $MyInvocation.MyCommand.Definition
[string]$currentSource = Get-Content $scriptFile
[int]$startScript=$currentSource.LastIndexOf("<QueryPropertiesTemplate");
[int]$closeComment=$currentSource.LastIndexOf("#>");
$xmlFile=[xml]($currentSource.Substring($startScript,$closeComment-$startScript))
$xmlFile.QueryPropertiesTemplate.QueryProperties.FarmId=$farmID.ToString()
$xmlFile.QueryPropertiesTemplate.QueryProperties.SiteId=$siteColId.ToString()
$xmlFile.QueryPropertiesTemplate.QueryProperties.WebId=$topLevelSiteID.ToString()
$xmlFile.OuterXml | Out-File queryparametertemplate.xml
$tempFile=Get-Item -LiteralPath "queryparametertemplate.xml"
$folder = $list.RootFolder
$stream=$tempFile.OpenRead()
$file = $folder.Files.Add($folder.Url+"/queryparametertemplate.xml",$stream,$true, "created by script",$false)
$stream.Close()
if($null -ne $file)
{
Write-Host ("File Created At " + $rootWeb.Url + "/" + $file.Url)
}
Write-Host " "
}
<#
<QueryPropertiesTemplate xmlns="http://www.microsoft.com/sharepoint/search/KnownTypes/2008/08" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<QueryProperties i:type="KeywordQueryProperties">
<EnableStemming>true</EnableStemming>
<FarmId>22222222-fa49-4987-b1ea-9fad99e81a0f</FarmId>
<SiteId>11111111-68f0-41c5-a525-7e7fda7666b3</SiteId>
<WebId>00000000-8d97-40a2-b07b-cf05e4c85084</WebId>
<IgnoreAllNoiseQuery>true</IgnoreAllNoiseQuery>
<KeywordInclusion>AllKeywords</KeywordInclusion>
<SummaryLength>180</SummaryLength>
<TrimDuplicates>true</TrimDuplicates>
<WcfTimeout>120000</WcfTimeout>
<Properties xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringanyType>
<a:Key>_IsEntSearchLicensed</a:Key>
<a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>EnableSorting</a:Key>
<a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>MaxKeywordQueryTextLength</a:Key>
<a:Value i:type="b:int" xmlns:b="http://www.w3.org/2001/XMLSchema">4096</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>TryCache</a:Key>
<a:Value i:type="b:boolean" xmlns:b="http://www.w3.org/2001/XMLSchema">true</a:Value>
</a:KeyValueOfstringanyType>
</Properties>
<PropertiesContractVersion>15.0.0.0</PropertiesContractVersion>
<EnableFQL>false</EnableFQL>
<EnableSpellcheck>Suggest</EnableSpellcheck>
<EnableUrlSmashing>true</EnableUrlSmashing>
<IsCachable>false</IsCachable>
<MaxShallowRefinementHits>100</MaxShallowRefinementHits>
<MaxSummaryLength>185</MaxSummaryLength>
<MaxUrlLength>2048</MaxUrlLength>
<SimilarType>None</SimilarType>
<SortSimilar>true</SortSimilar>
<TrimDuplicatesIncludeId>0</TrimDuplicatesIncludeId>
<TrimDuplicatesKeepCount>1</TrimDuplicatesKeepCount>
</QueryProperties>
<WhiteList xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:string>RowLimit</a:string>
<a:string>SortList</a:string>
<a:string>StartRow</a:string>
<a:string>RefinementFilters</a:string>
<a:string>Culture</a:string>
<a:string>RankingModelId</a:string>
<a:string>TrimDuplicatesIncludeId</a:string>
<a:string>ReorderingRules</a:string>
<a:string>EnableQueryRules</a:string>
<a:string>HiddenConstraints</a:string>
<a:string>QueryText</a:string>
<a:string>QueryTemplate</a:string>
<a:string>SelectProperties</a:string>
<a:string>SourceID</a:string>
</WhiteList>
</QueryPropertiesTemplate>
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment