pnp / powershell

PnP PowerShell
https://pnp.github.io/powershell
MIT License
658 stars 341 forks source link

[BUG] #326

Closed subhasishmukhopadhyay closed 3 years ago

subhasishmukhopadhyay commented 3 years ago

Reporting an Issue or Missing Feature

Please confirm what it is that your reporting

Issue in Azure function.

Expected behavior

Please describe what output you expect to see from the PnP PowerShell Cmdlets Simple as per the example

Actual behavior

Getting the below error when running the code with credentials without MFA RROR: AADSTS65001: The user or administrator has not consented to use the application with ID '31359c7f-bd7e-475c-86db-fdb8c937548e' named 'PnP Management Shell'. Send an interactive authorization request for this user and resource.

Steps to reproduce behavior

As present in the example https://pnp.github.io/powershell/articles/azurefunctions.html

using namespace System.Net

param($Request, $TriggerMetadata)

Write-Host "PowerShell HTTP trigger function processed a request."

$script = { $securePassword = ConvertTo-SecureString $env:tenant_pwd -AsPlainText -Force $credentials = New-Object PSCredential ($env:tenant_user, $securePassword)

Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/demo -Credentials $credentials

$web = Get-PnPWeb;
$web.Title

}

$webTitle = Start-ThreadJob -Script $script | Receive-Job -Wait

$body = "The title of the web is $($webTitle)"

Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ StatusCode = [HttpStatusCode]::OK Body = $body })

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

(you can retrieve this by executing Get-Module -Name "PnP.PowerShell" -ListAvailable) Azure function executing in web.

Which operating system/environment are you running PnP PowerShell on?

erwinvanhunen commented 3 years ago

Have you, as the error mentions, consented for the PnP Management Shell application in your tenant? See https://pnp.github.io/powershell/articles/authentication.html

gautamdsheth commented 3 years ago

You need to first register the PnP Management Shell Azure AD app in your M365 tenant. You can follow the article here -

https://pnp.github.io/powershell/articles/authentication.html

and the cmdlet doc:

https://pnp.github.io/powershell/cmdlets/Register-PnPManagementShellAccess.html

Once, the Azure AD app is installed in your tenant, your code should start working.

subhasishmukhopadhyay commented 3 years ago

Thanks a lot, I did now and it works.