Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Access Denied from a Azure Function App by Managed Identity #4817

Open
khha opened this issue Mar 28, 2025 · 0 comments
Open

[BUG] Access Denied from a Azure Function App by Managed Identity #4817

khha opened this issue Mar 28, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@khha
Copy link

khha commented Mar 28, 2025

Expected behavior

I expect that the script upload a file into a SharePoint library

Actual behavior

I got an access denied:

2025-03-28T16:03:40Z [Information] INFORMATION: Site statistics Report Generated Successfully C:\home\data\M365StatisticsReport-28-03-2025-04-03-17.csv
2025-03-28T16:03:40Z [Information] OUTPUT: Save file on C:\home\data\M365StatisticsReport-28-03-2025-04-03-17.csv
2025-03-28T16:03:40Z [Information] OUTPUT: Connect to site: https://myCompany.sharepoint.com/teams/biinput
2025-03-28T16:03:40Z [Information] OUTPUT: Site title: BI Input
2025-03-28T16:03:42Z [Error] ERROR: Toegang geweigerd. (this is in dutch Access denied)

Exception :
Type : System.Management.Automation.PSInvalidOperationException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Toegang geweigerd. (this is in dutch Access denied)
HResult : -2146233087
CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : InvalidOperation
TargetSite :
Name : ProcessRecord
DeclaringType : [PnP.PowerShell.Commands.Base.PnPConnectedCmdlet]
MemberType : Method
Module : PnP.PowerShell.dll
Message : Toegang geweigerd. (this is in dutch Access denied)
Source : PnP.PowerShell
HResult : -2146233079
StackTrace :
at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 101
at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo : InvalidOperation: (:) [Add-PnPFile], PSInvalidOperationException
FullyQualifiedErrorId : InvalidOperation,PnP.PowerShell.Commands.Files.AddFile
InvocationInfo :
MyCommand : Add-PnPFile
ScriptLineNumber : 75
OffsetInLine : 1
HistoryId : 1
ScriptName : C:\home\site\wwwroot\GetM365StatisticsReport\run.ps1
Line : Add-PnPFile -Path "C:\home\data\M365StatisticsReport-18-03-2025-08-00-53.csv" -Folder "$($destinationLibrary)" | Out-Null

Statement        : Add-PnPFile -Path "C:\home\data\M365StatisticsReport-18-03-2025-08-00-53.csv" -Folder "$($destinationLibrary)"
PositionMessage  : At C:\home\site\wwwroot\GetM365StatisticsReport\run.ps1:75 char:1
                   + Add-PnPFile -Path "C:\home\data\M365StatisticsReport-18-03-2025-08-00 …
                   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot     : C:\home\site\wwwroot\GetM365StatisticsReport
PSCommandPath    : C:\home\site\wwwroot\GetM365StatisticsReport\run.ps1
InvocationName   : Add-PnPFile
CommandOrigin    : Internal

ScriptStackTrace : at , C:\home\site\wwwroot\GetM365StatisticsReport\run.ps1: line 75

Steps to reproduce behavior

Create an Azure Function app with language PowerShell Core. Enable managed identity. Give the managed identity full control permissions on SharePoint Online. Create a new function where you try to upload a file into a SharePoint library.

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

2.12.0

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

  • [ X] Azure Functions
@khha khha added the bug Something isn't working label Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant