Skip to content

Bug report: Access Denied error when running newer versions of CLI in an Azure Function #4229

@martinlingstuyl

Description

@martinlingstuyl

Description

With version 5.8 I could install the CLI on an Azure PowerShell Function and run it successfully.

Since a recent version this now throws an error: Access Denied / System.Management.Automation.RemoteException exception.

I have an inkling this has to do with the CLI trying to access the file system. In 5.9 Shell tracking was introduced, for which the file system is used as a cache: #3769

The file system on an Azure Function cannot just be accessed in any place. The wwwroot should be okay though.

image

CLI for Microsoft 365 version

6.1

nodejs version

16

Operating system (environment)

Windows / Azure Function

Shell

PowerShell

Steps to reproduce:

  1. Create an Azure Function / PowerShell / Windows based
  2. Open Kudu
  3. navigate to wwwroot
  4. Install CLI LOCALLY(!) npm install @pnp/cli-microsoft365@next
  5. Wait 20 minutes until its installed
  6. Open the App Service Editor
  7. Add the following lines to profile.ps1:
Write-Host "Setting up m365 in PATH variable"
Write-Host "Current Path: $($Env:Path)" 

$functionPath = "$PWD\node_modules\.bin" 
if ($Env:PATH.Contains($functionPath) -eq $false) {
    [System.Environment]::SetEnvironmentVariable('PATH',$Env:PATH + ";$functionPath")
}

Write-Host "Changed Path: $($Env:Path)" 

This is to ensure the locally installed cli can be reached from the path

  1. Create a TimerTrigger and add m365 version in the code.
  2. Run the TimerTrigger

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions