Forum Discussion

Will_Hoch's avatar
Will_Hoch
Copper Contributor
Aug 22, 2022

Connect-SPOService Unexpected token error

Hello,

 

This is my first post ever so I apologize if I am missing obvious details.

 

I am writing a script in PowerShell that requires connecting SharePoint and I am doing so with the Connect-SPOService cmdlet. As it is a script I need to be able to connect with no interaction. This is the code I have been trying:

 

Connect-SPOService -Url 'link-to-our-admin-sharepoint' -Credential (Get-Secret -Vault VaultName -Name LoginInfo)

 

The Get-Secret is using the SecretManagement module which I have used before. In fact I have been able to do almost the exact same syntax with Connect-AzureAD and Connect-ExchangeOnline with no issues. The resulting exception is:

I know unexpected token errors usually mean a syntax error but 'center' literally doesn't exist. I suspect it has something to do with Get-Secret but as I said it works fine with other credential cmdlets using the same form. The account does not have MFA and Enable Legacy Authentication is set to true.

 

Thanks

 

Edit: When I try -credential <my-email> and enter the password manually I still get the same error so I suppose it has nothing to do with Get-Secret.

  • Will_Hoch 

     

    A cursory search on google points to this:

    The most likely causes of the error are as follows:
    
        the UPN of the admin account used to connect to SharePoint Online contains special characters, for example - or _, or
        the admin account has abnormal/non-standard values defined in other properties.
    
    There are two known solutions to the problem:
    
        Use the UPN with the default onmicrosoft.com domain name (e.g. email address removed for privacy reasons) to connect to SharePoint Online in CodeTwo Backup.
        Use another global admin account (global admin or SharePoint admin) to configure a SharePoint connection in the program. Preferably, create a fresh account that does not include any problematic configuration or special characters in its UPN.

     

    https://www.codetwo.com/userguide/backup/troubleshooting-sharepoint.htm

  • raindropsdev's avatar
    raindropsdev
    Iron Contributor

    Will_Hoch 

     

    A cursory search on google points to this:

    The most likely causes of the error are as follows:
    
        the UPN of the admin account used to connect to SharePoint Online contains special characters, for example - or _, or
        the admin account has abnormal/non-standard values defined in other properties.
    
    There are two known solutions to the problem:
    
        Use the UPN with the default onmicrosoft.com domain name (e.g. email address removed for privacy reasons) to connect to SharePoint Online in CodeTwo Backup.
        Use another global admin account (global admin or SharePoint admin) to configure a SharePoint connection in the program. Preferably, create a fresh account that does not include any problematic configuration or special characters in its UPN.

     

    https://www.codetwo.com/userguide/backup/troubleshooting-sharepoint.htm

    • Will_Hoch's avatar
      Will_Hoch
      Copper Contributor
      Changing the login email to the default onmicrosoft.com did the trick. Thanks.
      • Trying to reproduce but I still can't, also using SecretManagement

        Are you using a PSCredential?

        What version of the management shell?

Resources