Skip to content

Commit 51130ac

Browse files
authored
Create sharepoint-add-managed-identity.ps1
1 parent 9047368 commit 51130ac

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This script will grant the Managed Identity the correct permissions to the SharePoint site
2+
3+
#The user running this has to be owner of the SharePoint sitem and be sharepoint admin
4+
5+
# Add the correct 'Application (APP) ID' and 'displayName' for the Managed Identity
6+
$application = @{
7+
id = "APP ID"
8+
displayName = "APP DISPLAY NAME"
9+
}
10+
11+
# Add the correct role to grant the Managed Identity (read or write)
12+
$appRole = "write"
13+
14+
# Add the correct SharePoint Online tenant URL and site name
15+
#$spoTenant = "miljodir.sharepoint.com"
16+
$spoSite = "SITE ID"
17+
18+
# No need to change anything below
19+
#$spoSiteId = $spoTenant + ":/sites/" + $spoSite + ":"
20+
21+
Import-Module Microsoft.Graph.Sites
22+
Connect-MgGraph -Scope Sites.FullControl.All
23+
24+
#New-MgSitePermission -SiteId $spoSiteId -Roles $appRole -GrantedToIdentities @{ Application = $application }
25+
26+
New-MgSitePermission -SiteId $spoSite -Roles $appRole -GrantedToIdentities @{ Application = $application }
27+
28+
#To check the permissions run the following command
29+
#get-mgsitepermission -siteid $spoSite | format-list

0 commit comments

Comments
 (0)