-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisable Access request.ps1
39 lines (33 loc) · 1.16 KB
/
Disable Access request.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
#Function to disable access request SPO
Function Disable-PnPAccessRequest
{
[cmdletbinding()]
Param(
[parameter(Mandatory = $true, ValueFromPipeline = $True)] $Web
)
Try {
Write-host -f Yellow "Disabling Access Request on:"$web.Url
If($Web.HasUniqueRoleAssignments)
{
#Disable Access Request
$Web.RequestAccessEmail = [string]::Empty
$Web.SetUseAccessRequestDefaultAndUpdate($False)
$Web.Update()
Invoke-PnPQuery
Write-host -f Green "`tAccess Request has been Disabled!"$web.Url
}
else
{
Write-host -f Yellow "`tWeb inherits permissions from the parent!"$web.Url
}
}
Catch {
write-host "`tError Disabling Access Request: $($_.Exception.Message)" -foregroundcolor Red
}
}
#Parameter
$SiteURL = "https://fudsk.sharepoint.com"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Call the Function for all webs
Get-PnPSubWeb -IncludeRootWeb -Recurse -Includes HasUniqueRoleAssignments | ForEach-Object { Disable-PnPAccessRequest $_ }