简体   繁体   中英

Unable to Use SharePoint PNP PowerShell in VSCode

Running this command in VScode doesn't work but it works in PowerShellPlus.

Connect-PnPOnline -Url "https://something.sharepoint.com/" -Credentials $userCredential

Error:

   System.MissingMethodException: Method not found: 'System.Runtime.Remoting.ObjectHandle System.Activator.CreateInstance(System.String, System.String)'.
   at SharePointPnP.PowerShell.Commands.Base.ConnectOnline.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()

I've tried uninstalling VScode and removing any trace of SharePoint my machine but I'm not able to get past this error. Any ideas?

Edit: Following this blog post, I removed and reinstalled the SP PNP module.https://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=802

  1. Delete all the SharePoint Components from the Control Panel (Add/Remove)
  2. Open the GAC location (C:\\windows\\Microsoft.NET\\assembly\\GAC_MSIL), search for the term SharePoint and delete all the folders. (This is required since the reference is still old which is used by the PnP commands)
  3. Re-Start the machine
  4. Install the latest version of the SharePoint PnP

Here is how I fixed my issue:
1. In VSCode open the Command Palette on Windows or Linux with Ctrl+Shift+P. On macOS, use Cmd+Shift+P.
2. Search for Session.
3. Click on PowerShell: Show Session Menu.
4. Choose one of the ___ (x86) options

I was using x64 and that clearly didn't work.

Please don't uninatll the SharePoint trace in your machine and make sure you have install the corresponding PnP PowerShell library:

SharePoint/PnP-PowerShell

Then in VSCode, please install the PowerShell plugin:

在此处输入图片说明

Open the .ps1 which saved PnP PowerShell code and press F5 to run and debug:

在此处输入图片说明 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM