-
Notifications
You must be signed in to change notification settings - Fork 30
/
Get-SPManagedMetadataServiceTerms.ps1
210 lines (151 loc) · 6.31 KB
/
Get-SPManagedMetadataServiceTerms.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<#
$Metadata = @{
Title = "Get SharePoint Managed Metadata Service Terms"
Filename = "Get-SPManagedMetadataServiceTerms.ps1"
Description = ""
Tags = "powershell, function, sharepoint, managed, metadata, terms, export"
Project = ""
Author = "Janik von Rotz"
AuthorContact = "http://janikvonrotz.ch"
CreateDate = "2014-03-31"
LastEditDate = "2014-03-31"
Url = ""
Version = "1.0.0"
License = @'
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Switzerland License.
To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ch/ or
send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
'@
}
#>
function Get-SPManagedMetadataServiceTerms{
<#
.SYNOPSIS
List all Terms from Managed Metadata service.
.DESCRIPTION
List all Terms form a specifified term store and optionally filter them by term group.
.PARAMETER Site
Site running a taxonomy session.
.PARAMETER TermGroup
Optionally filter the term group.
.EXAMPLE
PS C:\> Get-SPManagedMetadataServiceTerms -Site "http://SharePoint.domain.com"
.EXAMPLE
PS C:\> Get-SPManagedMetadataServiceTerms -Site "http://SharePoint.domain.com" -TermGroup "Wiki"
.LINK
http://technet.microsoft.com/en-us/library/ee424396(v=office.14).aspx
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[String]
$Site,
[String]
$TermGroup
)
#--------------------------------------------------#
# functions
#--------------------------------------------------#
function Add-ArrayLevelIndex{
param(
$Object,
$AttributeName,
$Level = 0
)
# check the child attribute containing the same type of objects
$Objects = iex "`$Object.$AttributeName"
# output this item
$Object | select @{L="Object";E={$_}}, @{L="Level";E={$Level}}
# output the child items of this object
if($Objects){
# add level
$Level ++
# loop trough the same function
$Objects | %{Add-ArrayLevelIndex -Object $_ -AttributeName $AttributeName -Level $Level}
}
}
#--------------------------------------------------#
# modules
#--------------------------------------------------#
if((Get-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue) -eq $null){Add-PSSnapin 'Microsoft.SharePoint.PowerShell'}
#--------------------------------------------------#
# main
#--------------------------------------------------#
$SPTaxonomies = @()
$TempTerm = New-Object -TypeName Psobject @{
Index = ""
Term = ""
}
$i = 0;
$TempTerms = while($i -ne 7){
$i ++
$e = $TempTerm.PSObject.Copy()
$e.Index = $i
$e
}
# get all taxonomy objects
$SPTaxonomies = Get-SPTaxonomySession -Site $Site | %{
$_.TermStores | %{
$TermStore = New-Object -TypeName Psobject -Property @{
TermStore = $_.Name
"Term Group" = ""
"Term Set Name" = ""
"Term Set Description" = ""
LCID = ""
"Available for Tagging" = ""
Terms = ""
}
$_.Groups | Where{$_.Name -eq $TermGroup -or -not $TermGroup} | ForEach-Object{
$Group = $TermStore.PSObject.Copy()
$Group.'Term Group' = $_.Name
$_.TermSets | %{
$TermSet = $Group.PSObject.Copy()
$TermSet.'Term Set Name' = $_.Name
$TermSet.'Term Set Description' = $_.Description
$TermSet.Terms = ($_.Terms | %{Add-ArrayLevelIndex -Object $_ -AttributeName "Terms" -Level 1})
$TermSet
}
}
}
}
# get maximum of levels a term has
# $Levels = ($SPTaxonomies | %{$_.Terms | %{$_.Level}} | measure -Maximum).Maximum + 1
# or comment out and use default 7
# loop throught term stores
$SPTaxonomies | %{
$SPTaxonomy = $_
# Output Termstore definitions
$Item = $SPTaxonomy.PSObject.Copy()
$Item.'Available for Tagging' = if($_.IsAvailableForTagging){"TRUE"}else{"FALSE"}
$i = 0;while($i -ne 7){
$i ++
$Item | Add-Member –MemberType NoteProperty –Name "Level $i Term" –Value ""
}
$Item | Select-Object 'Term Set Name','Term Set Description', LCID, 'Available for Tagging', 'Term Description', 'Level*'
# loop throught terms
$_.Terms | where{$_} | %{
$Term = $_
# create a term export object
$Item = $SPTaxonomy.PSObject.Copy()
$Item.'Available for Tagging' = if($_.IsAvailableForTagging){"TRUE"}else{"FALSE"}
$Item.'Term Set Name' = ""
$Item.'Term Set Description' = ""
$_.Object.Labels | ForEach-Object{
$Item.LCID = $_.Language
$Index = 0;while($Index -ne 7){
$Index ++
if($Term.Level -eq $Index){
$Item | Add-Member –MemberType NoteProperty –Name "Level $Index Term" –Value $Term.Object.Name
$TempTerms[$Index].Term = $Term.Object.Name
}elseif($Index -gt $Term.Level){
$Item | Add-Member –MemberType NoteProperty –Name "Level $Index Term" –Value $Value
}elseif($Term.Level -gt $Index){
$Item | Add-Member –MemberType NoteProperty –Name "Level $Index Term" –Value $TempTerms[$Index].Term
}
}
}
# output this object
$Item | Select-Object 'Term Set Name','Term Set Description', LCID, 'Available for Tagging', 'Term Description', 'Level*'
}
}
}