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--
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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:
I checked scopes with "(Get-MgContext).Scopes", Admin consent is done everywhere needed.
Anyone any idea, I would appriciate
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--
Yes, I tried connecting with "Connect-MgGraph -Scopes "Sites.FullControl.All" ". Approved permissions by Global Admin and it is still not working ...
Next thing to check is whether you have give right permission to Microsoft Graph as below:
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--
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).
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.