PnP PowerShell: Bad Request when attempting to create a PnPAzureAD App

428 views Asked by At

When running the following command on PowerShell 7.2: Register-PnPAzureADApp -ApplicationName TestApp -Tenant yourtenant.onmicrosoft.com -Store CurrentUser -Username "[email protected]" -Password (Read-Host -AsSecureString -Prompt "Enter Password")

A bad request error is returned on execution: Register-PnPAzureADApp: {"error":{"code":"Request_BadRequest","message":"A null value was found with the expected type 'Edm.String[Nullable=False]'. The expected type 'Edm.String[Nullable=False]' does not allow null values.","innerError":{"date":"2023-07-31T14:21:28","request-id":"7dbf66db-f159-45dc-b061-7a1dcdc9e323","client-request-id":"7dbf66db-f159-45dc-b061-7a1dcdc9e323"}}}

Does anybody have some insight as to what might be the issue with the command? I am unsure if it is an issue with my environment or some other factor. Any help is appreciated! :)

Following Azure AD App Only Authentication in SharePoint Online using PnP PowerShell and expected to have obtained a certificate that I could use in my Azure-Functions application.

3

There are 3 answers

0
Justin Lyon On BEST ANSWER

I ended up using a wrong build of PnP.PowerShell, installing the nightly build with: Install-Module PnP.PowerShell -Scope CurrentUser -AllowPrerelease -SkipPublisherCheck Did the trick!

2
Venkat V On

The error you encountered while running the Register-PnPAzureADApp cmdlet indicates that there might be an issue with the parameters being passed to the cmdlet. The error message specifically mentions that a null value was found with an expected type that does not allow null values.

I tried the same command in my environment, and it created the application successfully.

  Register-PnPAzureADApp -ApplicationName TestApp1 -Tenant abc..com -Store CurrentUser -Username "Abc..com" -Password (Read-Host -AsSecureString -Prompt "Enter Password")

Output:

enter image description here

enter image description here

If you are still facing the issue with the above command, try the below commands to create an AzureAD application

Method 1:

Try with App-Only authentication: Instead of using the -Username and -Password parameters for user-based authentication, you can try using app-only authentication with Interactive mode.

Register-PnPAzureADApp -ApplicationName SPSitesSelected -Tenant abc.com -Store CurrentUser -SharePointApplicationPermissions "Sites.Selected" -Interactive

Method 2:

Try with App-Only Authentication: Instead of using the -Username and -Password parameters for user-based authentication, you can try using app-only authentication with a certificate.

Register-PnPAzureADApp -ApplicationName TestApp -Tenant abc.com -CertificatePath c:\certificate.pfx -CertificatePassword (ConvertTo-SecureString -String "password" -AsPlainText -Force) -Username "[email protected]" -Password (Read-Host -AsSecureString -Prompt "Enter password")

Reference: Register-PnPAzureADApp

0
domino On

In case it's useful for anyone, I had the same error when running this in the "new" PowerShell (7.4.1) against PnP.PowerShell 2.2.0. However, it worked on the same machine via "old" PowerShell (5.1.19041.4046) against PnP.PowerShell 1.11.0.