I want to automate one task in Office 365 by using powershell and for this I registered an app in AAD (V2 endpoint https://apps.dev.microsoft.com) and given access to MS Graph API with permissions "Have full access to all site collections", "Read and Write all groups" (and so on) access to the app. I am able to get the O365 group details via below PnP powershell commands but I am not sure how to get the context of SharePoint site or how to connect to a SP site within the same PS script by utilizing the same App credentials.

Connect-PnPOnline -AppId '<App Id>' -AppSecret '<App Secret>' -AADDomain 'tenant.onmicrosoft.com'
$group = Get-PnPUnifiedGroup -Identity 'hello team'
$spSiteUrl = $group.SiteUrl

Any tips how can I connect to SPO site?

1 Answer 1


I tried to access SharePoint site with Azure AD Oauth but getting access denied.

Sample code like:

$connection=Connect-PnPOnline -Url 'https://tenant.sharepoint.com/sites/Developer' -AppId 'GUID' -AppSecret 'secret' -ReturnConnection 



Then, i did research found this seems a known case.



So, you could try to register a SharePoint add-in and use add-in only policy for this case(the first thread).

  • Thanks. Yes, I am aware of the method mentioned in first link and thats the standard way of creating the app credential in SPO but I was expecting that if I can use the same app principal for which i have given access to MS Graph API and SPO sites. Is it so that i have to create two app principals then? Aug 19, 2018 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.