-
Notifications
You must be signed in to change notification settings - Fork 1
/
New-StartAddress.ps1
71 lines (61 loc) · 2.1 KB
/
New-StartAddress.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<#
.SYNOPSIS
Creates a new Content Source Start Address
.DESCRIPTION
Creates a new Content Source Start Address
Used to avoid issue with the "attempted to perform an unauthorised operation"
error (which succeeds anyway) when not running this on a machine hosting search
25/06/2015 - Original work created for MinRole Scenario Testing
.NOTES
File Name : New-StartAddress.ps1
Author : Spencer Harbar ([email protected])
Requires : PowerShell Version 2.0
.LINK
.PARAMETER File
The configuration file
#>
[CmdletBinding()]
#region PARAMS
param (
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[ValidateNotNullorEmpty()]
[String]$SearchServiceAppName,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=2)]
[ValidateNotNullorEmpty()]
[String]$ProfileStartAddress
)
#endregion PARAMS
begin {
If ((Get-PSSnapin -Name "Microsoft.SharePoint.PowerShell" -EA 0) -eq $null) { Add-PSSnapin -Name "Microsoft.SharePoint.PowerShell" }
$Server = $env:COMPUTERNAME
Write-Output "$(Get-Date -Format T) : Creating $ProfileStartAddress on $Server..."
}
process {
try {
$SearchServiceApp = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceAppName
$contentSource = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $SearchServiceApp
If ($contentSource.StartAddresses | Where-Object {$_.OriginalString -eq $ProfileStartAddress})
{
Write-Output "$(Get-Date -Format T) : Start Adress $ProfileStartAddress already exists!"
}
Else
{
$ContentSource.StartAddresses.Add($ProfileStartAddress) #MUST RUN ON SEARCH BOX TO AVOID ERROR
$ContentSource.Update()
}
}
catch {
Write-Host "OOOPS! We failed during creating $ProfileStartAddress on $Server." -ForegroundColor Red
$_
Exit
}
}
end {
Write-Output "$(Get-Date -Format T) : Created $ProfileStartAddress on $Server!"
}
#EOF