Connect-PnpOnline not working for access token

Amol Khairnar 0 Reputation points
2023-08-15T10:43:58.7766667+00:00

I am facing issue while connecting to SharePoint online using Access token -

$accessToken = <Generated using 'Client Secret' & 'Client Id' , Rest query returns access token>

Connect-PnPOnline -AccessToken $accessToken -Url $SiteURL -ReturnConnection

It seems some versioning conflict please help as it was taking long time to troubleshoot.

Issue:

Get-PnPList : Cannot convert 'System.Object[]' to the type 
'PnP.PowerShell.Commands.Base.PnPConnection' required by parameter 
'Connection'. Specified method is not supported.
At C:\Users\PS111426\Desktop\<folder>\OD-comparions.ps1:29 char:60
+ ... cList = Get-PnPList -Identity $libTitle -Connection $SiteConn -Includ ...
+                                                         ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-PnPList], ParameterBin 
   dingException
    + FullyQualifiedErrorId : CannotConvertArgument,PnP.PowerShell.Commands.Li 
   sts.GetList
 

Microsoft 365 and Office | SharePoint | Development
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-08-16T02:34:37.58+00:00

    Hi @Amol Khairnar

    Judging from the error message you provided, the place where the error is reported is:

    • ... cList = Get-PnPList -Identity $libTitle -Connection $SiteConn -Includ ...

    Cannot convert 'System.Object[]' to the type 'PnP.PowerShell.Commands.Base.PnPConnection' required by parameter 'Connection'. Specified method is not supported.

    The cause of the error is: you are passing an array of connections instead of a single connection to the -Connection parameter of Get-PnPList.

    You can check the type of the $SiteConn variable with Get-Type $SiteConn and make sure it is a PnP.PowerShell.Commands.Base.PnPConnection object, not a System.Object[] array.

    You could also try using the -Web parameter instead of the -Connection parameter to specify the Web where the list is located.


    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.

    Was this answer helpful?

    0 comments No comments

Your answer

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