Skip to content

Commit

Permalink
Create sharepoint-add-managed-identity.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
kasovr authored Dec 12, 2024
1 parent 9047368 commit 51130ac
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions MGGraph/sharepoint-add-managed-identity.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This script will grant the Managed Identity the correct permissions to the SharePoint site

#The user running this has to be owner of the SharePoint sitem and be sharepoint admin

# Add the correct 'Application (APP) ID' and 'displayName' for the Managed Identity
$application = @{
id = "APP ID"
displayName = "APP DISPLAY NAME"
}

# Add the correct role to grant the Managed Identity (read or write)
$appRole = "write"

# Add the correct SharePoint Online tenant URL and site name
#$spoTenant = "miljodir.sharepoint.com"
$spoSite = "SITE ID"

# No need to change anything below
#$spoSiteId = $spoTenant + ":/sites/" + $spoSite + ":"

Import-Module Microsoft.Graph.Sites
Connect-MgGraph -Scope Sites.FullControl.All

#New-MgSitePermission -SiteId $spoSiteId -Roles $appRole -GrantedToIdentities @{ Application = $application }

New-MgSitePermission -SiteId $spoSite -Roles $appRole -GrantedToIdentities @{ Application = $application }

#To check the permissions run the following command
#get-mgsitepermission -siteid $spoSite | format-list

0 comments on commit 51130ac

Please sign in to comment.