Skip to content

Commit

Permalink
More search related scripts
Browse files Browse the repository at this point in the history
Added more search related scripts
  • Loading branch information
jcgonzalezmartin committed Jul 6, 2014
1 parent 0615dc7 commit f4c3bc6
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 0 deletions.
32 changes: 32 additions & 0 deletions SharePoint/Search/PS_Get_Query_Suggestions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
############################################################################################################################################
# Script that allows to get all the query suggestions already defined in a SharePoint farm.
# Required Parameters:
# ->$sTheasurusFilePath: Theasurus File Path
############################################################################################################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that gets current query suggestions in the SharePoint farm
function Get-QuerySuggestions
{
try
{
Write-Host "Getting all the query suggestions..." -ForegroundColor Green
$ssaSearchApp = Get-SPEnterpriseSearchServiceApplication -Identity Search Service App"
$spSearchOwner = Get-SPEnterpriseSearchOwner -Level SSA
Get-SPEnterpriseSearchQuerySuggestionCandidates -SearchApplication $ssaSearchApp -Owner $spSearchOwner
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

Start-SPAssignment –Global
Get-QuerySuggestions
Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell
61 changes: 61 additions & 0 deletions SharePoint/Search/PS_Import_Query_Suggestions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
############################################################################################################################################
# Script that allows to import query suggestions to the SharePoint Search.
# Required Parameters:
# ->$sInputfile: Query suggestions file.
# ->$sLanguage: Language for the Query Suggestions.
############################################################################################################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that imports new query suggestions to SharePoint
function Import-QuerySuggestions
{
param ($sInpuntFile,$sLanguage)
try
{
Write-Host "Importing Query Suggestions.." -ForegroundColor Green
#Checking if the query suggestions file exists
$bFileExists = (Test-Path $sInputFile -PathType Leaf)
if ($bFileExists) {
"Loading $sInputFile for processing..."
$tblData = Import-CSV $sInputFile
} else {
Write-Host "File $sInputFile not found. Stopping the Import Process!" -foregroundcolor Red
exit
}

$ssaSearchApp = Get-SPEnterpriseSearchServiceApplication -Identity Search Service App"
$spSearchOwner = Get-SPEnterpriseSearchOwner -Level SSA

#Processing the file data
foreach ($row in $tblData){
$sQuerySuggestion=$row.QuerySuggestion.ToString()
Write-Host "Adding $sQuerySuggestion as a Query Suggestion"
New-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssaSearchApp -Language $sLanguage -Type QuerySuggestionAlwaysSuggest -Name $sQuerySuggestion -Owner $spSearchOwner
}

#Starting the Timer Job that makes available new query suggestions
$qsTimerJob = Get-SPTimerJob -type "Microsoft.Office.Server.Search.Administration.PrepareQuerySuggestionsJobDefinition"
Write-Host "Starting " $qsTimerJob.Name " Timber Job" -ForegroundColor Green
$qsTimerJob.RunNow()
Write-Host "Query Suggestions successfully imported!!" -ForegroundColor Green

}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

Start-SPAssignment –Global
#Archivo con los Usuarios
$ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
$sInputFile=$ScriptDir+ "\QuerySuggestions_Madrid.txt"
$sLanguage="ES-es"
Import-QuerySuggestions -sInpuntFile $sInputFile -sLanguage $sLanguage
Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell
43 changes: 43 additions & 0 deletions SharePoint/Search/PS_Remove_SearchQuerySuggestions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
############################################################################################################################################
# Script that allows to remove query suggestions from the SharePoint Search.
# Required Parameters:
# ->$sQuerySuggestion: Query suggestion to rmeove
# ->$sLanguage: Language for the Query Suggestions.
############################################################################################################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that removes a query suggestion from the SharePoint Search
function Remove-QuerySuggestions
{
param ($sQuerySuggestion,$sLanguage)
try
{
Write-Host "Removing Query Suggestion $sQuerySuggestion" -ForegroundColor Green
$ssaSearchApp = Get-SPEnterpriseSearchServiceApplication -Identity Search Service App"
$spSearchOwner = Get-SPEnterpriseSearchOwner -Level SSA
Remove-SPEnterpriseSearchLanguageResourcePhrase -SearchApplication $ssaSearchApp -Language $sLanguage -Type QuerySuggestionAlwaysSuggest -Identity $sQuerySuggestion -Owner $spSearchOwner -Confirm:$false

#Starting the Timer Job that makes available new query suggestions
$qsTimerJob = Get-SPTimerJob -type "Microsoft.Office.Server.Search.Administration.PrepareQuerySuggestionsJobDefinition"
Write-Host "Starting " $qsTimerJob.Name " Timber Job" -ForegroundColor Green
$qsTimerJob.RunNow()
Write-Host "Query Suggestion $sQuerySuggestion successfully removed!!" -ForegroundColor Green

}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

Start-SPAssignment –Global
$sLanguage="ES-es"
$sQuerySuggestion="Atlético de Madrid"
Remove-QuerySuggestions -sQuerySuggestion $sQuerySuggestion -sLanguage $sLanguage
Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell
5 changes: 5 additions & 0 deletions SharePoint/Search/QuerySuggestions_Madrid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
QuerySuggestion
Madrid
Real Madrid
Atlético de Madrid
Comunidad de Mardid
37 changes: 37 additions & 0 deletions SharePoint/Utils/PS_FindCorrelationIDInLogs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
############################################################################################################################################
# Script that allows to find all the ocurrences for a Correlation ID in the SharePoint Loigs
# Required Parameters:
# -> $sCorrelationID: Correlation ID to look for
# -> $sLogFile: Name of the log file where the information obtained is stored
############################################################################################################################################

If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell }

$host.Runspace.ThreadOptions = "ReuseThread"

#Definition of the function that finds a specific correlation ID in SharePoint Log Files
function Find-CorrelationID
{
param ($sCorrelationID,$sLogFile)
try
{
Write-Host "Finding the correlation ID $sCorrelationID in SharePoint Logs" -foregroundcolor Green
Get-SPLogEvent | ?{$_.Correlation -eq $sCorrelationID} | select Area, Category, Level, EventID, Message | Format-List > $sLogFile
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}

Start-SPAssignment –Global
#Calling the function
$sCorrelationID="9fd3251e-b81f-45f8-b2b7-044b64418f55"
$sScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path
$sLogFile=$sScriptDir + "\CorrelationIDLog.log"
Find-CorrelationID -sCorrelationID $sCorrelationID -sLogFile $sLogFile
Stop-SPAssignment –Global

Remove-PSSnapin Microsoft.SharePoint.PowerShell

0 comments on commit f4c3bc6

Please sign in to comment.