Guest User

Untitled

a guest
Mar 18th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
  2.  
  3. function Get-NormalizedString
  4. {
  5. [cmdletbinding()]
  6. param
  7. (
  8. [Parameter(Mandatory=$true)][string]$String
  9. )
  10.  
  11. ($String.Trim() -replace '\uFF06', '&' ) -replace '\uFF02', '"'
  12. }
  13.  
  14. function Get-TermPath
  15. {
  16. [cmdletbinding()]
  17. param
  18. (
  19. [Parameter(Mandatory=$true)][Microsoft.SharePoint.Taxonomy.Term]$Term
  20. )
  21.  
  22. begin
  23. {
  24. }
  25. process
  26. {
  27. Write-Verbose -Message "Starting Term: $($Term.Name)"
  28.  
  29. foreach( $t in $Term.Terms )
  30. {
  31. Write-Verbose -Message "Sub-Term: $($t.Name)"
  32. Get-TermPath -Term $t
  33. }
  34.  
  35. Write-Verbose -Message "Ending Term: $($Term.Name)"
  36.  
  37. New-Object PSCustomObject -Property @{
  38. Term = Get-NormalizedString -String $Term.Name
  39. Path = Get-NormalizedString -String $Term.GetPath().Replace(";", " > ")
  40. TermSet = $Term.TermSet.Name
  41. }
  42. }
  43. end
  44. {
  45. }
  46. }
  47.  
  48.  
  49. function Export-TermStoreGroup
  50. {
  51. [cmdletbinding()]
  52. param
  53. (
  54. [Parameter(Mandatory=$true)][Microsoft.SharePoint.SPSite]$Site,
  55. [Parameter(Mandatory=$true)][string[]]$GroupName
  56. )
  57.  
  58. begin
  59. {
  60. $session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($Site)
  61. $results = @()
  62. }
  63. process
  64. {
  65. foreach( $termStore in $session.TermStores )
  66. {
  67. Write-Verbose -Message "TermStore: $($termStore.Name)"
  68.  
  69. foreach( $group in $termStore.Groups | ? { $GroupName -contains $_.Name } )
  70. {
  71. Write-Verbose -Message "`tTermGroup: $($group.Id)"
  72.  
  73. foreach( $termSet in $group.TermSets )
  74. {
  75. Write-Verbose -Message "`t`tTermSet: $($termSet.Name)"
  76.  
  77. foreach( $term in $termSet.Terms )
  78. {
  79. Get-TermPath -Term $term
  80. }
  81. }
  82. }
  83. }
  84. }
  85. end
  86. {
  87. $results
  88. }
  89. }
  90.  
  91.  
  92. Export-TermStoreGroup -Group "TERM GROUP NAME" -Site (Get-SPSite -Limit 1 -WarningAction SilentlyContinue) |
  93. SORT TermSet, Term, Path |
  94. SELECT TermSet, Term, Path |
  95. Export-Csv -Path "C:\_temp\TermGroupExport.csv" -NoTypeInformation
Add Comment
Please, Sign In to add comment