Need Assistance to grant an Azure Service Principal permission to a Specific M365 SharePoint Site in our tenant #10235
Replies: 4 comments 12 replies
-
@Smileyville I think you might be mixing the PowerShell modules you want to use, or you are using and that could explain why you get syntax error as from what I understand you are trying to use SP (SharePoint Server PowerShell dedicated for OnPrem versions) cmdlets together with SPO (SharePoint Online Management Shell which is supposed to be used with SharePoint Online only). At the beginning you mention using Set-SPAppPrincipalPermission. Then you reference this guide which actually is using SharePoint Online Management Shell. This is something totally different and this is a PowerShell module you may use on your local machine (outside of any SharePoint Server) to manage SharePoint Online. Aim of this module is to manage SharePoint Online not on Prem. You also may use this module only in windows PowerShell (the old blue terminal) not PowerShell 5 or 7 or higher versions. All command that are Both of the above you may use only in windows PowerShell (old powershell) and the SharePoint Server should rather be used only within SharePoint Management Shell which is only present on SharePoint server machine. what I think you are doing wrong is you are importing the SharePoint Online Management Shell and trying to use additional info (just to bring more clarity You may also stumble upon a 3rd option which is PnP PowerShell. This is a modern and community driven PowerShell module also to manage SharePoint Online only. This may be used in modern PowerShell like v7 and its commands are and then last but not least (best option IMO 😜) you may find CLI for Microsoft 365 which is CLI tool you may run in any shell (not only PowerShell) and on any kind of machine (Windows, Mac, Linux etc.) that allows you to manage Microsoft 365 (and SharePoint Online along as well). It has totally different way of specifying commands and is totally different tech than the above. Happy Coding! |
Beta Was this translation helpful? Give feedback.
-
Hello. Thank you for your response, you are probably right on mixing the syntax for the different modules. I am definitely just wanting to do this from the SharePoint Online perspective as that is where the site is in SharePoint Online (M365) and Azure where the Service Principal is. I do think the PowerShell version is an issue. I get errors when trying either flavor. I will try your last suggestion of the CLI and see if it gets me past the hurdle. I appreciate your help. |
Beta Was this translation helpful? Give feedback.
-
Following your recommendation to install the M365 shell, https://pnp.github.io/cli-microsoft365/, I am going to sound like a newbie but how exactly? Via PowerShell or Command Line they don't recognize the cmdlet, etc. |
Beta Was this translation helpful? Give feedback.
-
Trying the syntax here, https://learn.microsoft.com/en-us/powershell/module/sharepoint-online/set-spoapplicationpermission?view=sharepoint-ps, Maybe we are not approaching correctly. Ultimately, Databricks is the one using the Service Principal to connect to SharePoint Online. So the developer trying to accomplish this is simply trying to call the Service Principal's information that was input into the Keyvault to connect to the SharePoint site to retrieve data. This is a sample of their code which they are using in a Databricks notebook to connect, which may help in getting us setup the next steps - as currently this always fails with a token access error which seems to imply the permission is not applied which circles back to what I'm trying to do with the syntax errors.
Thanks for your help. |
Beta Was this translation helpful? Give feedback.
-
Hello. I had originally opened tickets with Microsoft support from Azure & M365 pointed me to this area instead of providing assistance so hope you can help.
We have created an Azure Service Principal and are planning to use the SP to connect to a specific M365 SharePoint site within our tenant.
We have followed the documentation that MS provides, https://learn.microsoft.com/en-us/powershell/module/sharepoint-server/set-spappprincipalpermission?view=sharepoint-server-ps and https://learn.microsoft.com/en-us/answers/questions/2116616/service-principal-access-to-sharepoint-online
The syntax however does not work properly and get errors indicating that that the Syntax is incorrect, not recognizing Get-SPSite, Get AppPrincipalPermission, etc. I have verified that the SPO modules are all installed.
One of the techs had me generate the SP from the SharePoint side, https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs which worked fine. However; once again, trying to connect via the SP provides errors indicating the syntax is not correct.
Please provide any assistance you can in the appropriate syntax via PowerShell to map the SP and SharePoint site regardless if created from SharePoint Online into Azure or starting in Azure and trying to grant permission to SharePoint online site.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions