Guest User

Untitled

a guest
Apr 17th, 2017
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. c:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Search.dll
  2.  
  3. #Please install the SharePoint client components SDK - http://www.microsoft.com/en-us/download/details.aspx?id=35585 prior to running this script.
  4.  
  5. #Specify tenant admin, site URL and scope to export from
  6. $SiteURL = https://tenant.sharepoint.com/sites/site
  7. $Scope = "SPSite"
  8. $Schema = "D:SearchSchema.XML"
  9.  
  10. #Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
  11. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
  12. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  13. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Search.dll"
  14.  
  15. $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
  16. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
  17.  
  18. #Export search configuration
  19. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
  20. $Context.Credentials = $Creds
  21. $Owner = New-Object Microsoft.SharePoint.Client.Search.Administration.SearchObjectOwner($Context,$Scope)
  22. $Search = New-Object Microsoft.SharePoint.Client.Search.Portability.SearchConfigurationPortability($Context)
  23. $SearchConfig = $Search.ExportSearchConfiguration($Owner)
  24. $Context.ExecuteQuery()
  25. $SearchConfig.Value > $Schema
  26.  
  27. $searchConfigurationPortability = New-Object Microsoft.SharePoint.Client.Search.Portability.SearchConfigurationPortability($clientContext)
  28. $owner = New-Object Microsoft.SharePoint.Client.Search.Administration.SearchObjectOwner($clientContext, $configScope)
  29.  
  30. [xml]$searchConfigXml = Get-Content $pathToSearchSchemaXmlFile
  31. $searchConfigurationPortability.ImportSearchConfiguration($owner, $searchConfigXml.OuterXml)
  32. $clientContext.ExecuteQuery()
  33.  
  34. <#
  35. .SYNOPSIS
  36. Add managed properties to the Search Service Application.
  37.  
  38. .DESCRIPTION
  39. Add managed properties to the Search Service Application.
  40.  
  41. .NOTES
  42. File Name: Create-ManagedProperty.ps1
  43. Author : Bart Kuppens
  44. Version : 1.0
  45.  
  46. .PARAMETER ConfigFile
  47. Specifies the location and name of the config file which contains the properties that need to be created.
  48.  
  49. .PARAMETER SearchAppName
  50. Specifies the name of the Search Service Application.
  51.  
  52. .EXAMPLE
  53. PS > .Create-ManagedProperty.ps1 -ConfigFile "c:tempmanagedproperty.xml" -SearchAppName "Enterprise Search Service"
  54. #>
  55. [CmdletBinding()]
  56. param(
  57. [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the URL of the Web Application.")]
  58. [string]$ConfigFile,
  59.  
  60.  
  61. [Parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the name of the Search Service Application.")]
  62. [string]$SearchAppName
  63. )
  64.  
  65.  
  66. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
  67. {
  68. Write-Host "Loading SharePoint cmdlets..."
  69. Add-PsSnapin Microsoft.SharePoint.PowerShell
  70. }
  71.  
  72. #get the XML file
  73. if (!$ConfigFile)
  74. {
  75. Write-Host "Could not find the configuration file specified. Aborting execution!" -ForegroundColor red
  76. Break
  77. }
  78.  
  79. Write-Host "Parsing file: " $file
  80. [System.Xml.XmlDocument]$XmlDoc = [xml](Get-Content $file)
  81.  
  82. $searchapp = Get-SPEnterpriseSearchServiceApplication $SearchAppName
  83.  
  84.  
  85.  
  86. # Add Managed Properties
  87. $PropertyNodeList = $XmlDoc.SearchConfiguration.ManagedProperties
  88. foreach ($PropertyNode in $PropertyNodeList.ManagedProperty)
  89. {
  90. $SharePointProp = $PropertyNode.Name
  91. $SharePointPropType = $PropertyNode.Type
  92. $SharePointPropMapList = $PropertyNode.Map
  93.  
  94. if ($mp = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $SharePointProp -ea "silentlycontinue")
  95. {
  96. Write-Debug -Message [$mp]
  97. $mp.DeleteAllMappings()
  98. $mp.Delete()
  99. $searchapp.Update()
  100. }
  101. New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $SharePointProp -Type $SharePointPropType
  102. $mp = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $SharePointProp
  103. foreach ($SharePointPropMap in $SharePointPropMapList)
  104. {
  105. $SPMapCat = $SharePointPropMap.Category
  106. $SPMapName = $SharePointPropMap.InnerText
  107. $cat = Get-SPEnterpriseSearchMetadataCategory –SearchApplication $searchapp –Identity $SPMapCat
  108. $prop = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $cat -Name $SPMapName
  109. New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -CrawledProperty $prop -ManagedProperty $mp
  110. }
  111. }
  112.  
  113. <Deployment>
  114. <Solutions SolutionSourceDir="">
  115. <!--WebApplication: Provide the destination web application where to deploy the solution-->
  116. <!-- - Use a * to deploy to all web applications-->
  117. <!-- - Leave empty if solution is a global solution-->
  118. <Solution SolutionName="" WebApplication="http://sp10/" />
  119. </Solutions>
  120. <Configuration>
  121. <SearchSettings>
  122. <MetadataProperties>
  123. <CrawledProperties>
  124. <CrawledProperty Name="ows_mtes_ExerciseSeries" DataType="Text"/>
  125. <CrawledProperty Name="ows_mtes_ExercisePhase" DataType="Text"/>
  126. <CrawledProperty Name="ows_mtes_StaffFunction" DataType="Text"/>
  127. <CrawledProperty Name="ows_mtes_DocumentType" DataType="Text"/>
  128. </CrawledProperties>
  129. <ManagedProperties>
  130. <ManagedProperty Name="mtesExerciseSeries" DataType="1" OptimizedProperty="True" >
  131. <Map Category="SharePoint">ows_mtes_ExerciseSeries</Map>
  132. </ManagedProperty>
  133. <ManagedProperty Name="mtesExercisePhase" DataType="1" >
  134. <Map Category="SharePoint">ows_mtes_ExercisePhase</Map>
  135. </ManagedProperty>
  136. <ManagedProperty Name="mtesStaffFunction" DataType="1" >
  137. <Map Category="SharePoint">ows_mtes_StaffFunction</Map>
  138. </ManagedProperty>
  139. <ManagedProperty Name="mtesDocumentType" DataType="1" >
  140. <Map Category="SharePoint">ows_mtes_DocumentType</Map>
  141. </ManagedProperty>
  142. </ManagedProperties>
  143. </MetadataProperties>
  144. </SearchSettings>
  145.  
  146. </Configuration>
  147. </Deployment>
Advertisement
Add Comment
Please, Sign In to add comment