-
Notifications
You must be signed in to change notification settings - Fork 30
/
Get-SPLists.ps1
109 lines (76 loc) · 2.56 KB
/
Get-SPLists.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
<#
$Metadata = @{
Title = "Get SharePoint Lists"
Filename = "Get-SPLists.ps1"
Description = ""
Tags = ""powershell, sharepoint, function"
Project = ""
Author = "Janik von Rotz"
AuthorContact = "http://janikvonrotz.ch"
CreateDate = "2013-07-29"
LastEditDate = "2013-10-11"
Version = "3.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-SPLists{
<#
.SYNOPSIS
Get all SharePoint lists.
.DESCRIPTION
Get all SharePoint lists.
.PARAMETER SPWeb
Url or PowerShell object of the SharePoint website.
.PARAMETER OnlyDocumentLibraries
Only get document libraries
.PARAMETER Recursive
Requires Identity, includes the every sub list of the specified website.
.EXAMPLE
PS C:\> Get-SPLists -Object "http://sharepoint.vbl.ch/Projekte/SitePages/Homepage.aspx" -OnlyDocumentLibraries -Recursive
#>
param(
[Parameter(Mandatory=$false)]
$SPWeb,
[Parameter(Mandatory=$false)]
[string]$FilterListName,
[switch]$OnlyDocumentLibraries,
[switch]$Recursive
)
#--------------------------------------------------#
# modules
#--------------------------------------------------#
if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
}
#--------------------------------------------------#
# main
#--------------------------------------------------#
$(if($SPWeb){
$SPWebUrl = (Get-SPUrl $SPWeb).Url
if($Recursive){
Get-SPWebs -Url $SPWebUrl
}else{
Get-SPWeb -Identity $SPWebUrl
}
}else{
Get-SPWebs
}) | %{
$_.lists | %{
$(if($FilterListName){
$_ | where{$_.Title -eq $FilterListName}
}else{
$_
}) | %{
$(if($OnlyDocumentLibraries){
$_ | where {$_.BaseType -eq "DocumentLibrary"}
}else{
$_
})
}
}
}
}