Pnp-powershell: Almost all cmdlets return (400) Bad Request on PowerShell 7

Created on 26 Mar 2020  路  16Comments  路  Source: pnp/PnP-PowerShell

Reporting an Issue or Missing Feature

Issue

Expected behavior

In the default installation of PowerShell with Windows (5.1.18362.628) I am able to use PnP-PowerShell.

Connect-PnPOnline -Url https://mycompany.sharepoint.com/sites/MyTestSite -UseWebLogin
Get-PnPUser

This successfully returns results.

Actual behavior

Running the exact same commands in PowerShell 7 returns Get-PnPUser: The remote server returned an error: (400) Bad Request.

I get the same error for Get-PnPSite, Get-PnPView, and Get-PnPRecycleBinItem.

Steps to reproduce behavior

  1. Install PowerShell 7.0.0 win-x64. I have reproduced this issue with both the MSI and the ZIP versions.
  2. Run PowerShell 7's pwsh.exe
  3. Install PnP-PowerShell (Install-Module SharePointPnPPowerShellOnline -Scope CurrentUser)
  4. Connect to a site (Connect-PnPOnline -Url https://mycompany.sharepoint.com/sites/MyTestSite -UseWebLogin)
  5. Run a command that fetches data from SharePoint (Get-PnPRecycleBinItem -firststage)
  6. Observe the error message.

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [x] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

3.19.2003.0

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means
Needs

Most helpful comment

I'm experiencing the same issues, is there a more permanent fix than the one of @Markus-Hanisch ?

All 16 comments

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

I used Fiddler to monitor the requests and have learned some additional details.

In the version of PowerShell that comes with Windows when I run Get-PnPUser it makes a POST /sites/MyTestTeam/_vti_bin/sites.asmx request with the following body:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUpdatedFormDigestInformation xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
  </soap:Body>
</soap:Envelope>

When I run the same command in PowerShell 7 the POST /sites/MyTestTeam/_vti_bin/sites.asmx request has no body. (Content-Length: 0)

I am getting the same behaviour with Connect-PnPOnline with Powershell v7.0. Works with Powershell v5.

Connect-PnPOnline works for me, it's just subsequent commands that fail. Is Connect-PnPOnline itself failing for you @fredericklin?

That's correct. I'm connecting directly to a site collection and it is calling the same endpoint.

POST https://tenant.sharepoint.com/sites/testsite/_vti_bin/sites.asmx HTTP/1.1

Also

HTTP/1.1 400 Bad Request
Content-Length: 0

Can confirm - same issue for me - Connect-PnPOnline works, anything else fails with 400 (example - Add-PnPTenantTheme

@JoshuaWalsh @GavinHaak @fredericklin
Well, I don't know the latest info on Module compatibility, but in this blog post Announcing PowerShell 7.0 from March 4th, 2020 mentioned the following:

Which Microsoft products already support PowerShell 7?
Any module that is already supported by PowerShell Core 6.x is also supported in PowerShell 7, including:
Azure PowerShell (Az.*)
Active Directory
Many of the modules in Windows 10 and Windows Server (check with Get-Module -ListAvailable)
On Windows, we鈥檝e also added a -UseWindowsPowerShell switch to Import-Module to ease the transition to PowerShell 7 for those using still incompatible modules. This switch creates a proxy module in PowerShell 7 that uses a local Windows PowerShell process to implicitly run any cmdlets contained in that module. For more information on this functionality, check out the Import-Module documentation.

For those modules still incompatible, we鈥檙e working with a number of teams to add native PowerShell 7 support, including Microsoft Graph, Office 365, and more.

Azure Cloud Shell has already been updated to use PowerShell 7, and others like the .NET Core SDK Docker container images and Azure Functions will be updated soon.

Based on that information, I checked if there is PowerShell Core compatible module for SharePointPnPPowerShellOnline:

Get-Module -ListAvailable -Name "SharePointPnPPowerShell*"

Result: PSEdition is stated as "Desk" - Windows PowerShell so to say or else no PowerShell Core compatible module.

Furthermore, I tested your described issue and received no error.

Import-Module SharePointPnPPowerShellOnline -UseWindowsPowerShell
Connect-PnPOnline -Url "https://<tenant>-admin.sharepoint.com"
Get-PnPUser -Identity "i:0#.f|membership|<user>"

Works like a charm.

Thanks @Markus-Hanisch

Using -UseWindowsPowerShell does indeed make the commands work correctly. Is there an existing issue for adding native support for PowerShell 7 to this module?

EDIT: I'm still encountering this issue if I use PnP-PowerShell with the new -Parallel switch on ForEach-Object.

1..5 | ForEach-Object -Parallel { Connect-PnPOnline -Url https://mycompany.sharepoint.com/sites/MyTestSite } -ThrottleLimit 2

I also tried:

1..5 | ForEach-Object -Parallel { Import-Module SharePointPnPPowerShellOnline; Connect-PnPOnline -Url https://mycompany.sharepoint.com/sites/MyTestSite } -ThrottleLimit 2

With both of these commands I get a 400 response due to POST /sites/MyTestTeam/_vti_bin/sites.asmx having no body.

Of course I tried just running the actual command I want to run within ForEach-Object without re-connecting, but that gives me "No connection, please connect first with Connect-PnPOnline". It seems connections from the host thread aren't shared with ForEach-Object -Parallel children.

I'm experiencing the same issues, is there a more permanent fix than the one of @Markus-Hanisch ?

Any progress on this issue? It would be great to be able to use PnP in the latest Azure Functions runtime for powershell functions (which is pscore7)

Jumping on the bandwagon. Encountered the error on Connect-PnPOnline in PowerShell 7.0.3, Google sent me here.

Bumping this one as well. using the -UseWindowsPowerShell is nice, but not really useful on Azure functions runtime 3.
I am kind of stuck here with this. Want to use Azure Queue Storage, which needs PS7, and want to do PnP commands with the powershell script, but that need PS5.

Any timeline on support for PS7?
Finally found valid information it is indeed not supported: (https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-pnp-provisioning#create-the-azure-function)

Still the information there is outdated, as you can't create runtime 1 anymore https://docs.microsoft.com/en-US/azure///azure-functions/functions-versions, and Azure Function creation no defaults to runtime 3, with only support for PowerShell Core (7). You can change it to runtime 2 later, but you are stuck with PowerShell Core (6.2). So newly created Azure Function Apps have no way of using PnP-Powershell now

_Update: typo, + Add link to valid documents stating only Powershell is support and no PowerShell Core_

Same issue. PowerShell 7.0.3

There is a nightly build of the PnP PowerShell Core version now! https://github.com/pnp/powershell

hi @addyvandendoel .. the link is broken. I assume dev branch? Can you share the correct link
Thanks!

hi @mpriem https://github.com/pnp/powershell some disagreement with the forum editor and my. sorry about that. this should work.
There is also a roadmap there of the coming choices https://github.com/pnp/powershell#pnp-powershell-roadmap-status

Was this page helpful?
0 / 5 - 0 ratings