Get-MgSite : Access denied

Patryk Koprowski 6 Reputation points
2022-08-23T17:39:49.483+00:00

Hi All

I am having a lot of issues getting all sites with MS Graph in PowerShell.

Tried with delegated permissions and app-only and constantly getting access denied. Any one came across something similar?

Running: "Get-MgSite -SiteId root" works with no issues, returning site root.
When I try to run: Get-MgSite -Search "Contoso" I get below:

234155-image.png

I checked scopes with "(Get-MgContext).Scopes", Admin consent is done everywhere needed.

234173-image.png

Anyone any idea, I would appriciate

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,506 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,354 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Patryk Koprowski 6 Reputation points
    2022-08-24T07:20:19.557+00:00

    Yes, I tried connecting with "Connect-MgGraph -Scopes "Sites.FullControl.All" ". Approved permissions by Global Admin and it is still not working ...

    1 person found this answer helpful.
    0 comments No comments

  2. Manu Philip 16,961 Reputation points MVP
    2022-08-23T18:44:24.153+00:00

    Have you tried connecting the Graph first as below?
    Connect-MgGraph -Scopes "Sites.FullControl.All"

    ----------

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments

  3. Manu Philip 16,961 Reputation points MVP
    2022-08-24T07:55:25.637+00:00

    Next thing to check is whether you have give right permission to Microsoft Graph as below:

    234375-image.png

    234308-image.png

    Check, if the graph permissions are assigned correctly and Granted admin consent for the directory

    If this is also not helping, check your application access token in jwt.ms website and see if "Site.Read.All" and "Sites.ReadWrite.All" listed in in roles claim. If not, the token should be corrected

    ----------

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments

  4. RajeshKumarMSFT 1,971 Reputation points Microsoft Vendor
    2022-08-24T18:01:36.267+00:00

    Hi @Patryk Koprowski ,

    Hope you are doing well,

    I am able to get the site search results using Get-MgSite -Search "" cmdlet Please follow the attached screen shot and grant the required permissions (Scopes).

    234635-get-mgsite.png

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments