-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathIdentify-SharePoint-On-Premise-Permissions.ps1
95 lines (80 loc) · 3.28 KB
/
Identify-SharePoint-On-Premise-Permissions.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
Add-PSSnapin Microsoft.SharePoint.PowerShell
Add-Type -Path 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
$SiteUrl = "http://dev/sites/Testing"
#$SPSite = New-Object Microsoft.SharePoint.SPSite($SiteUrl);
$outfile = "uniqueUserPermissionsReport.csv"
$WebApps=Get-SPWebApplication
"Web Title,Web URL,List Title,User or Group,Role,Inherited" | out-file $outfile
#For all Web
foreach($SPSite in $WebApps.sites)
{
if ($SPSite.HasUniqueRoleAssignments)
{
$SPRoleAssignments = $SPSite.RoleAssignments;
foreach ($SPRoleAssignment in $SPRoleAssignments)
{
if($SPRoleAssignment.Member.GetType().Name -eq "SPUser")
{
foreach ($SPRoleDefinition in $SPRoleAssignment.RoleDefinitionBindings)
{
$SPSite.Title + "," + $SPSite.Url + "," + "N/A" + "," + $SPRoleAssignment.Member.Name + "," + $SPRoleDefinition.Name + "," + $SPSite.HasUniqueRoleAssignments | out-file $outfile -append
}
}
}
}
#For all SiteCollections
foreach ($web in $SPSite.AllWebs)
{
if ($web.HasUniqueRoleAssignments)
{
$SPRoleAssignments = $web.RoleAssignments;
foreach ($SPRoleAssignment in $SPRoleAssignments)
{
if($SPRoleAssignment.Member.GetType().Name -eq "SPUser")
{
foreach ($SPRoleDefinition in $SPRoleAssignment.RoleDefinitionBindings)
{
$web.Title + "," + $web.Url + "," + "N/A" + "," + $SPRoleAssignment.Member.Name + "," + $SPRoleDefinition.Name + "," + $web.HasUniqueRoleAssignments | out-file $outfile -append
}
}
}
}
#For all list
foreach ($list in $web.Lists)
{
if ($list.HasUniqueRoleAssignments)
{
$SPRoleAssignments = $list.RoleAssignments;
foreach ($SPRoleAssignment in $SPRoleAssignments)
{
if($SPRoleAssignment.Member.GetType().Name -eq "SPUser")
{
foreach ($SPRoleDefinition in $SPRoleAssignment.RoleDefinitionBindings)
{
$web.Title + "," + $web.Url + "," + $list.Title + "," + $SPRoleAssignment.Member.Name + "," + $SPRoleDefinition.Name | out-file $outfile -append
}
}
}
}
#for all list items
foreach ($item in $list.items)
{
if ($item.HasUniqueRoleAssignments)
{
$SPRoleAssignments = $item.RoleAssignments;
foreach ($SPRoleAssignment in $SPRoleAssignments)
{
if($SPRoleAssignment.Member.GetType().Name -eq "SPUser")
{
foreach ($SPRoleDefinition in $SPRoleAssignment.RoleDefinitionBindings)
{
$web.Title + "," + $web.Url + "," + $list.Title + "," +$item.Title + ","+ $SPRoleAssignment.Member.Name + "," + $SPRoleDefinition.Name | out-file $outfile -append
}
}
}
}
}
}
}
}
$SPSite.Dispose();