0

When running the following command on PowerShell 7.2: Register-PnPAzureADApp -ApplicationName TestApp -Tenant yourtenant.onmicrosoft.com -Store CurrentUser -Username "yourname@domain.com" -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.

2 Answers2

0

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 "yourname@domain.com" -Password (Read-Host -AsSecureString -Prompt "Enter password")

Reference: Register-PnPAzureADApp

Venkat V
  • 2,197
  • 1
  • 1
  • 10
  • I attempted both of these methods, creating both a Self-Signed Certificate and using the interactive mode, and both methods returned with the same result. I wish there was a way to know what value is tripping this error. – Justin Lyon Aug 01 '23 at 16:35
  • Try with Azure PowerShell, if still facing issue with Local PowerShell. – Venkat V Aug 02 '23 at 03:19
0

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!