Skip to content

Instantly share code, notes, and snippets.

@sodacrackers
Created October 30, 2016 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sodacrackers/f764ce1e8d0861eafd96c9847b96eec4 to your computer and use it in GitHub Desktop.
Save sodacrackers/f764ce1e8d0861eafd96c9847b96eec4 to your computer and use it in GitHub Desktop.
PowerShell to update SharePoint 2013 search content source start addresses from a remote RSS feed
Write-Host "---"
Write-Host "--- Starting job $MyInvocation.ScriptName"
Write-Host "--- Copies URLs from SharePoint list to the URLs list of a search content source"
Write-Host "---"
Add-PSSnapin Microsoft.SharePoint.PowerShell
function Execute-Updates {
[CmdletBinding()]
param()
process
{
Write-Host "--- Setting content source start addresses"
$urls = Get-Feed-URLs -RemoteFeedURLs @("http://www.washington.edu/news/category/health-and-medicine/feed")
$cs = Get-Search-Content-Source -SearchContentSource "WebTech Crawl"
Set-Content-Source-URLs -ContentSource $cs -StartAddresses $urls
}
}
function Get-Search-Content-Source {
[CmdletBinding()]
[OutputType([psobject])]
param(
[Parameter(Mandatory=$true)]
[string]
$SearchContentSource
)
process {
Write-Host "--- Getting SharePoint services"
Get-SPServiceApplication | ForEach-Object {
If ($_.TypeName -like "Search Service*") {
Write-Host "--- Getting search service: " $_.DisplayName
$sa = Get-SPServiceApplication $_.Id
}
}
Write-Host "--- Getting content sources"
$cs = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $sa
$cs | ForEach-Object {
If ($_.Name -like $SearchContentSource) {
Write-Host "--- Getting content source: " $_.Name
return $_
}
}
}
}
function Set-Content-Source-URLs {
[CmdletBinding()]
[OutputType([psobject])]
param(
[Parameter(Mandatory=$true)]
[psobject]
$ContentSource,
[Parameter(Mandatory=$true)]
[array]
$StartAddresses
)
process
{
Write-Host "--- Adding unique start addresses"
$addresses = $StartAddresses + $ContentSource.StartAddresses | Get-Unique
$addresses = $addresses -Join ", "
Write-Host "--- New addresses list: " $addresses
$cs | Set-SPEnterpriseSearchCrawlContentSource -StartAddresses "$addresses" -MaxSiteEnumerationDepth 0 -MaxPageEnumerationDepth 0
}
}
function Get-Feed-URLs {
[CmdletBinding()]
[OutputType([array])]
param(
[Parameter(Mandatory=$true)]
[array]
$RemoteFeedURLs
)
process
{
Write-Host "--- Getting URLs from feed address"
$links = @()
$RemoteFeedURLs | ForEach-Object {
Write-Host "--- Getting URLs from: " $_
$result = Invoke-WebRequest -Uri $_ -UseBasicParsing
[xml]$xml = $result.Content
$xml.SelectNodes('//channel/item') | ForEach-Object {
$links += $_.link
}
}
return $links
}
}
Execute-Updates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment