Basé sur différents scripts disponibles sur Internet, dont :
Ce script fonctionne sur SharePoint Server et SharePoint Foundation 2013 (validé sur la plateforme Foundation) :
Function AddSearchLocalContentSource
{
Try
{
[string]$serviceAppName = "Search Service Application" #Give the Search App Name
[string]$ContentSourceName = "Another Search Content"
[string]$ContentSiteurl = “http://mynewcontentURL”
[string]$ContentSourceType = "SharePoint" #specify the Type (Web, File, ….)Write-Host "Add the new content source : $ContentSourceName - $ContentSiteurl"
$SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $serviceAppName -ErrorAction SilentlyContinue
$ContentSources = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SearchServiceApplication
$ContentSources | ForEach-Object {
if ($_.Name.ToString() -eq $ContentSourceName)
{
Write-Host "Content Source : $ContentSourceName already exist. Deleting the Content source..."
Remove-SPEnterpriseSearchCrawlContentSource -SearchApplication $SearchServiceApplication -Identity $ContentSourceName -Confirm:$false
}
}
$SPContentSource = New-SPEnterpriseSearchCrawlContentSource -SearchApplication $SearchServiceApplication -Type $ContentSourceType -name $ContentSourceName -StartAddresses $ContentSiteurl -MaxSiteEnumerationDepth 0
if($SPContentSource.CrawlState -eq "Idle")
{
Write-Host "Starting the FullCrawl for the content source : $ContentSourceName"
$SPContentSource.StartFullCrawl()
do {Start-Sleep 2; Write-Host "." -NoNewline}
While ( $SPContentSource.CrawlState -ne "CrawlCompleting")
Write-Host ""
Write-Host "FullCrawl for the content source : $ContentSourceName completed."
}
}
catch [system.exception]
{
Write-Host -ForegroundColor Yellow " ->> Add the New Content Source caught a system exception"
Write-Host -ForegroundColor Red "Exception Message:", $_.Exception.ToString()
}
finally
{
Write-Host "--------------------------------------"
}
}
Vous pouvez inclure ce script dans votre fichier PowerShell pour gérer votre ferme.
Romelard Fabrice [MVP] - MBA Risk Management
Commentaires
Enregistrer un commentaire