-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCreate-CustomPermissionLevel.ps1
40 lines (36 loc) · 1.52 KB
/
Create-CustomPermissionLevel.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
<#
.SYNOPSIS
Create custom permission level
.DESCRIPTION
Create a custom permission level in SharePoint Online
.EXAMPLE
PS C:\> .\Create-CustomPermissionLevel.ps1
This will start the script and create a copy of the READ perm. level in the sites defined in your CSV file.
.INPUTS
Inputs (if any)
.OUTPUTS
Output (if any)
.NOTES
PLEASE REFER TO MY BLOG POST FOR MORE INFO ABOUT THE SCRIPT + ITS PURPOSE FOR YOUR BUSINESS NEEDS.
https://veronicageek.com/office-365/sharepoint-online/create-custom-permissions-for-multiple-site-collections-in-spo-using-powershell-pnp/2019/05/
#>
#Connect to SPO admin center --> Change to your TENANT NAME
$creds = Get-Credential
Connect-PnPOnline -Url https://<TENANT_NAME>-admin.sharepoint.com -Credentials $creds
#Import sites from .csv --> Change to your filepath
$mySites = Import-Csv -Path 'YOUR_FILE_PATH_LOCATION'
#Create all for each site
foreach ($site in $mySites) {
#Connect to each site
Write-Host "Connecting to $($site.SiteUrl)" -ForegroundColor Green
Connect-PnPOnline -Url $site.SiteUrl
#Create the NEW permission level (clone the 'READ' default permissions)
$PermToClone = Get-PnPRoleDefinition -Identity "Read"
$addPnPRoleDefinitionSplat = @{
Include = 'ManagePersonalViews', 'UpdatePersonalWebParts', 'AddDelPrivateWebParts'
Description = "Copy of Read + Personal Permissions"
RoleName = "myCustomPermLevel"
Clone = $PermToClone
}
Add-PnPRoleDefinition @addPnPRoleDefinitionSplat
}