0

We are using PnP powershell which works as expected. However, sometimes we face an exception intermittently with the error as given below. The PnP powershell script line is

Connect-PnPOnline -Url $DestinationSite -Credential (Get-Credential)

We are able to fix if we reinstall PnP module again. But what is the reason this issue keeps appearing intermittently?

**Connect-PnPOnline : The 'Connect-PnPOnline' command was found in the module 'SharePointPnPPowerShellOnline', but the module could not be loaded. For more information, run 'Import-Module SharePointPnPPowerShellOnline'. At C:\MyMigScript\04a StartOneDriveMigration.ps1:82 char:21 + Connect-PnPOnline ` + ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Could not load type 'Microsoft.SharePoint.Client.SearchBoxInNavBarType' from assembly 'Microsoft.SharePoint.Client, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. Connect-PnPOnline : The 'Connect-PnPOnline' command was found in the module 'SharePointPnPPowerShellOnline', but the module could not be loaded. For more information, run 'Import-Module SharePointPnPPowerShellOnline'. At C:\MyMigScript\04a StartOneDriveMigration.ps1:82 char:21 + Connect-PnPOnline ` + ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Could not load type 'Microsoft.SharePoint.Client.SearchBoxInNavBarType' from assembly 'Microsoft.SharePoint.Client, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. Connect-PnPOnline : The 'Connect-PnPOnline' command was found in the module 'SharePointPnPPowerShellOnline', but the module could not be loaded. For more information, run 'Import-Module SharePointPnPPowerShellOnline'. At C:\MyMigScript\04a StartOneDriveMigration.ps1:82 char:21 + Connect-PnPOnline ` + ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Connect-PnPOnline:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule**

2
  • You have an environment issue, or a problem with your script. If you just open the shell and run the command with no arguments, does it prompt you for the url and credentials? Do a little more troubleshooting and provide some more info on how you're running the script. Jan 3, 2020 at 13:52
  • @DerekGusoff - we face the error while also running the command Import-Module SharePointPnPPowerShellOnline. If we open a new session and try it after sometime it then works! Not sure what is the root cause of it though. Do you have any suggestions/pointers?
    – Avi
    Jan 5, 2020 at 4:30

2 Answers 2

0

Did you solve this issue? I came across the same issue with my codes. Finally, I found the way to solve it.

I am working on ASP.Net website which contain codes using PowerShell PnP to manipulate SharePoint. First I build a very simple website only containing the codes using PowerShell PnP. It works very good. Then I put these codes back to my old website which contain other codes using SharePoint CSOM, I got exactly the same error as you did.

I tried many different ways and found that it was due to the SharePoint CSOM. I updated the NuGet package of SharepointOnline.CSOM (See below image) to the latest version, that is the 16.1.20616.12000. Then the PowerShell PnP works perfectly fine!

So you could have a try!

Well, in case the image won't show up, I wrote the NuGet package here:

Microsoft.SharepointOnline.CSOM distrubuted by Microsoft

enter image description here

0

Late entry here, but... Look at the -UseWebLogin or -Interactive switches on the Connect-PnPOnline command.

Connect-PnPOnline
       [-ReturnConnection]
       [-Url] <String>
       [-TenantAdminUrl <String>]`
       [-UseWebLogin]
       [-Interactive]
       [-ForceAuthentication]

Connect-PnPOnline -Url "https://contoso.sharepoint.com" -UseWebLogin

Connect-PnPOnline -Url "https://contoso.sharepoint.com" -Interactive

See Here: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-ps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.