How to fix error: Add-PnPFile : There is currently no connection yet. Use Connect-PnPOnline to connect.

Anonymous
2024-12-05T12:54:49.0966667+00:00

Hi,

Issue Description: When running a PowerShell script to upload and check in files to SharePoint Online, the following errors are encountered despite using the Connect-PnPOnline command to establish a connection:

Error Messages:

Add-PnPFile : There is currently no connection yet. Use Connect-PnPOnline to connect.
At C:\filepath\script.ps1:115 char:13
+             Add-PnPFile -Path $sourceFilePath -Folder $sharePointPath ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-PnPFile], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,PnP.PowerShell.Commands.Files.AddFile

Set-PnPFileCheckedIn : There is currently no connection yet. Use Connect-PnPOnline to connect.
At C:\filepath\script.ps1:119 char:13
+             Set-PnPFileCheckedIn -Url $uploadedFilePath -CheckinType  ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-PnPFileCheckedIn], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,PnP.PowerShell.Commands.Files.SetFileCheckedIn

Steps taken:

  1. Ensured Connection: Verified that the
       Connect-PnPOnline -Url $siteUrl -Interactive
    
    command is executed before any other commands.
  2. Updated Module: Updated the PnP PowerShell module to the latest version using:
       Update-Module -Name PnP.PowerShell
    

Regards,

James

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

Answer accepted by question author
RaytheonXie_MSFT 40,496 Reputation points Microsoft External Staff
2024-12-06T02:46:41.7433333+00:00

Hi @James,

Have you set the environment variable for client id? Connects to the Azure AD, acquires an access token and allows PnP PowerShell to access both SharePoint and the Microsoft Graph. You will have to register your own App first, by means of Register-PnPEntraIDApp to use this method. You will also have to provide the -ClientId parameter starting September 9, 2024. Alternatively, create an environment variable, call it ENTRAID_APP_ID or ENTRAID_CLIENT_ID and set the value to the app id you created. If you use -Interactive and this environment variable is present you will not have to use -ClientId. You could refer to following

Connect-PnPOnline -Url "https://contoso.sharepoint.com" -Interactive -ClientId 6c5c98c7-e05a-4a0f-bcfa-0cfc65aa1f28


Here is the document for more details

https://pnp.github.io/powershell/cmdlets/Connect-PnPOnline.html


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?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.