Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Search.dll
- #Please install the SharePoint client components SDK - http://www.microsoft.com/en-us/download/details.aspx?id=35585 prior to running this script.
- #Specify tenant admin, site URL and scope to export from
- $User = "admin@tenant.onmicrosoft.com"
- $SiteURL = https://tenant.sharepoint.com/sites/site
- $Scope = "SPSite"
- $Schema = "D:SearchSchema.XML"
- #Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Search.dll"
- $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
- #Export search configuration
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
- $Context.Credentials = $Creds
- $Owner = New-Object Microsoft.SharePoint.Client.Search.Administration.SearchObjectOwner($Context,$Scope)
- $Search = New-Object Microsoft.SharePoint.Client.Search.Portability.SearchConfigurationPortability($Context)
- $SearchConfig = $Search.ExportSearchConfiguration($Owner)
- $Context.ExecuteQuery()
- $SearchConfig.Value > $Schema
- $searchConfigurationPortability = New-Object Microsoft.SharePoint.Client.Search.Portability.SearchConfigurationPortability($clientContext)
- $owner = New-Object Microsoft.SharePoint.Client.Search.Administration.SearchObjectOwner($clientContext, $configScope)
- [xml]$searchConfigXml = Get-Content $pathToSearchSchemaXmlFile
- $searchConfigurationPortability.ImportSearchConfiguration($owner, $searchConfigXml.OuterXml)
- $clientContext.ExecuteQuery()
- <#
- .SYNOPSIS
- Add managed properties to the Search Service Application.
- .DESCRIPTION
- Add managed properties to the Search Service Application.
- .NOTES
- File Name: Create-ManagedProperty.ps1
- Author : Bart Kuppens
- Version : 1.0
- .PARAMETER ConfigFile
- Specifies the location and name of the config file which contains the properties that need to be created.
- .PARAMETER SearchAppName
- Specifies the name of the Search Service Application.
- .EXAMPLE
- PS > .Create-ManagedProperty.ps1 -ConfigFile "c:tempmanagedproperty.xml" -SearchAppName "Enterprise Search Service"
- #>
- [CmdletBinding()]
- param(
- [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the URL of the Web Application.")]
- [string]$ConfigFile,
- [Parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the name of the Search Service Application.")]
- [string]$SearchAppName
- )
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
- {
- Write-Host "Loading SharePoint cmdlets..."
- Add-PsSnapin Microsoft.SharePoint.PowerShell
- }
- #get the XML file
- if (!$ConfigFile)
- {
- Write-Host "Could not find the configuration file specified. Aborting execution!" -ForegroundColor red
- Break
- }
- Write-Host "Parsing file: " $file
- [System.Xml.XmlDocument]$XmlDoc = [xml](Get-Content $file)
- $searchapp = Get-SPEnterpriseSearchServiceApplication $SearchAppName
- # Add Managed Properties
- $PropertyNodeList = $XmlDoc.SearchConfiguration.ManagedProperties
- foreach ($PropertyNode in $PropertyNodeList.ManagedProperty)
- {
- $SharePointProp = $PropertyNode.Name
- $SharePointPropType = $PropertyNode.Type
- $SharePointPropMapList = $PropertyNode.Map
- if ($mp = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $SharePointProp -ea "silentlycontinue")
- {
- Write-Debug -Message [$mp]
- $mp.DeleteAllMappings()
- $mp.Delete()
- $searchapp.Update()
- }
- New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $SharePointProp -Type $SharePointPropType
- $mp = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $SharePointProp
- foreach ($SharePointPropMap in $SharePointPropMapList)
- {
- $SPMapCat = $SharePointPropMap.Category
- $SPMapName = $SharePointPropMap.InnerText
- $cat = Get-SPEnterpriseSearchMetadataCategory –SearchApplication $searchapp –Identity $SPMapCat
- $prop = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $cat -Name $SPMapName
- New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -CrawledProperty $prop -ManagedProperty $mp
- }
- }
- <Deployment>
- <Solutions SolutionSourceDir="">
- <!--WebApplication: Provide the destination web application where to deploy the solution-->
- <!-- - Use a * to deploy to all web applications-->
- <!-- - Leave empty if solution is a global solution-->
- <Solution SolutionName="" WebApplication="http://sp10/" />
- </Solutions>
- <Configuration>
- <SearchSettings>
- <MetadataProperties>
- <CrawledProperties>
- <CrawledProperty Name="ows_mtes_ExerciseSeries" DataType="Text"/>
- <CrawledProperty Name="ows_mtes_ExercisePhase" DataType="Text"/>
- <CrawledProperty Name="ows_mtes_StaffFunction" DataType="Text"/>
- <CrawledProperty Name="ows_mtes_DocumentType" DataType="Text"/>
- </CrawledProperties>
- <ManagedProperties>
- <ManagedProperty Name="mtesExerciseSeries" DataType="1" OptimizedProperty="True" >
- <Map Category="SharePoint">ows_mtes_ExerciseSeries</Map>
- </ManagedProperty>
- <ManagedProperty Name="mtesExercisePhase" DataType="1" >
- <Map Category="SharePoint">ows_mtes_ExercisePhase</Map>
- </ManagedProperty>
- <ManagedProperty Name="mtesStaffFunction" DataType="1" >
- <Map Category="SharePoint">ows_mtes_StaffFunction</Map>
- </ManagedProperty>
- <ManagedProperty Name="mtesDocumentType" DataType="1" >
- <Map Category="SharePoint">ows_mtes_DocumentType</Map>
- </ManagedProperty>
- </ManagedProperties>
- </MetadataProperties>
- </SearchSettings>
- </Configuration>
- </Deployment>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement