Syntax error while running script(low trust) for App-Only Authentication for SharePoint Server (On-Premise )

Yichen Name 86 Reputation points
2023-02-20T08:46:38.9633333+00:00

Hello Team,

I am trying to get the access token for the SharePoint on prem versions, via app-only authentication. In the following thread your team has provided us options to achieve this: https://learn.microsoft.com/en-us/answers/questions/1162405/app-only-authentication-for-sharepoint-server-(on

We have tried with the low trust option and followed the same steps mentioned in following document https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/use-an-office-365-sharepoint-site-to-authorize-provider-hosted-add-ins-on-an-on to do the set up for App Only Authentication for on premise environment and during execution we faced syntax error when we executed the following command:

Connect-SPFarmToAAD -AADDomain 'sample.onmicrosoft.com' -SharePointOnlineUrl https://sample.sharepoint.com -SharePointWeb https://ec2-11-111-111-111.wi-center-0.compute.shp.com:10987/sites/TestSite

On executing above mentioned command we are getting the following error:


Set-MsolServicePrincipal : Invalid syntax.  Parameter Name: ServicePrincipalNames.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\MySharePointFunctions\MySharePointFunctions.psm1:103 char:9
+         Set-MsolServicePrincipal -AppPrincipalId $SPAppPrincipal.AppP ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Set-MsolServicePrincipal], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.StringSyntaxValidationException,Microsoft.Online.Administration.Automation.SetServicePrincipal

Could you please help and let us know how to resolve this error to proceed with the set up?

If possible, can we please connect over a meeting?

Thanks.

Microsoft 365 and Office SharePoint Server For business
{count} votes

2 answers

Sort by: Most helpful
  1. Yichen Name 86 Reputation points
    2023-02-21T13:14:27.9766667+00:00

    MySharePointFunctions.txt

    Hi Yanli Jiang - MSFT,

    Thanks for your reply. We have attached the file with this comment that contains the code Please have a look on that.

    we have used following command to execute the code:

    Connect-SPFarmToAAD -AADDomain 'sample.onmicrosoft.com' -SharePointOnlineUrl https://sample.sharepoint.com -SharePointWeb https://ec2-11-111-111-111.wi-center-0.compute.shp.com:10987/sites/TestSite
    

    Note: we have saved this file in a system with name MySharePointFunctions.psm1 but here editor not allowing with that extension that's why renamed it.

    Please let us know if we can have a call to discuss more on this.

    Thanks

    0 comments No comments

  2. Yanli Jiang - MSFT 31,596 Reputation points Microsoft External Staff
    2023-02-23T06:05:46.2866667+00:00

    According to your error message, it may be a problem with the storage location of your MySharePointFunctions.psm1 file.

    Did you save MySharePointFunctions.psm1 according to the steps in the article?

    The file has to be saved as ANSI format, not UTF-8. PowerShell may give syntax errors when it loads a file with a non-ANSI format. Windows NotePad defaults to saving it as ANSI. If you use any other editor to save the file, be sure you are saving it as ANSI.

    02232

    02233

    Please check.


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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

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