Share via

Grant Power Shell App access to only 1 Sites.Selected

Phil Tetreault 40 Reputation points
2026-05-21T21:57:50.68+00:00

How do I allow a Power Shell script to access and execute a script in a designated site and not have access across the tenant?

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

Answer accepted by question author

AI answer

2026-05-21T21:58:06.1+00:00

Use a Sites.Selected permission model and grant the PowerShell app access only to the specific site.

High-level steps:

  1. Register or identify the Microsoft Entra application used by the PowerShell script.
  2. Assign it only Sites.Selected (not Sites.Read.All or Sites.FullControl.All) in Microsoft Graph / SharePoint.
  3. Grant site-level permissions for just the target site using PnP PowerShell.

From the context, PnP PowerShell supports resource-specific consent (RSC) for SharePoint Online:

  1. Connect to the target site with PnP PowerShell (using an admin account):
       Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/TargetSite -Interactive
    
  2. Grant the Entra app permissions only on that site:
       Grant-PnPAzureADAppSitePermission \
         -AppId {client-id} \
         -DisplayName "PowerShell App" \
         -Permissions Write \
         -Site (Get-PnPSite)
    
    • {client-id} is the Entra app’s client ID used by the PowerShell script.
    • -Permissions can be Read, Write, Manage, or FullControl depending on what the script needs.

This grants the app access only to that specific site collection. Because the app has only Sites.Selected at the tenant level, it cannot access any other sites unless similar site-level permissions are granted elsewhere.

When running the PowerShell script, authenticate using that Entra app (for example via certificate-based auth with PnP PowerShell or Microsoft Graph SDK). The script will then be limited to the designated site.


References:

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.