-
Notifications
You must be signed in to change notification settings - Fork 0
/
Reset Site Permissions.ps1
75 lines (58 loc) · 3.59 KB
/
Reset Site 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
#Script to check and bereak inheritance of subsites of given site
# Configuration variables
$SiteURL = "http://XXXXXXXXXX"
$AuthorizedUserAccountName = "DomainName\0000-ADMINS" # User or Security Group
### DO NOT TOUCH THE CODE BELOW ###
# Required if not run in SharePoint Management Shell
if($ver.Version.Major -gt 1)
{
$Host.Runspace.ThreadOptions = "ReuseThread"
}
If((Get-PSSnapin -Name Microsoft.Sharepoint.Powershell -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.Sharepoint.Powershell
}
function Break-Inheritance($url)
{
$web = Get-SPWeb $url;
Write-Output "Processing $($web.Title)";
$web.BreakRoleInheritance($true);
$account = $web.EnsureUser($AuthorizedUserAccountName);
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account);
$role = $web.RoleDefinitions["Full Control"];
$assignment.RoleDefinitionBindings.Add($role);
$web.RoleAssignments.Add($assignment);
$web.Dispose();
}
function Set-Inheritance($url)
{
$web = Get-SPWeb $url;
Write-Output "Processing $($web.Title)";
$web.ResetRoleInheritance();
$web.Dispose();
}
function Reset-Inheritance($url)
{
Break-Inheritance($url);
Set-Inheritance($url);
}
Function Check-Inheritance($url)
{
$web = Get-SPWeb $url;
Write-Output "Processing $($web.Title)";
$result = $web.HasUniqueRoleAssignments;
$web.Dispose();
return $result;
}
Function Get-AllWebs($url)
{
Get-SPSite $url -Limit All | Get-SPWeb -Limit All | Select Url;
}
Get-AllWebs $SiteURL | Foreach-Object { Check-Inheritance($_.url) }
#Get-AllWebs "http://xxxxxxxxxxxxxx" | Foreach-Object {
# If ( Check-Inheritance($_.url) -eq $true)
# {
#
# Reset-Inheritance($_.url)
# }
#}