Advertisement
Guest User

Untitled

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