pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
990 stars 663 forks source link

[BUG] Error when loading recent version of SharePointPnPPowershellOnline module in Azure Function v1 #2803

Open PRusakPL opened 4 years ago

PRusakPL commented 4 years ago

Reporting an Issue or Missing Feature

When using recent version of SharePointPnPPowershellOnline module (ver 3.23.2007.1) in Azure Function v1 (runtime: powershell) I receive Import-Module errors and whole Azure Function fails. It looks module uses Windows Registry as a dependency - and this is forbidden when trying to load module in Azure Function.

Expected behavior

Ability to load recent version of SharePointPnPPowerShellOnline module in Azure Function v1 without any errors.

Actual behavior

When SharePointPnPPowerShellOnline module (in version 3.23.2007.1) is loaded in Azure Function I receive following errors:

Import-Module : A drive with the name 'HKLM' already exists. + Import-Module + _____ + CategoryInfo : ResourceExists: (HKLM:String) [Import-Module], ProviderInvocationException + FullyQualifiedErrorId : DriveAlreadyExists,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : A drive with the name 'Alias' already exists. + Import-Module + _____ + CategoryInfo : ResourceExists: (Alias:String) [Import-Module], ProviderInvocationException + FullyQualifiedErrorId : DriveAlreadyExists,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : A drive with the name 'Env' already exists. + Import-Module + _____ + CategoryInfo : ResourceExists: (Env:String) [Import-Module], ProviderInvocationException + FullyQualifiedErrorId : DriveAlreadyExists,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : A drive with the name 'C' already exists. + Import-Module + _____ + CategoryInfo : ResourceExists: (C:String) [Import-Module], ProviderInvocationException + FullyQualifiedErrorId : DriveAlreadyExists,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : A drive with the name 'Function' already exists. + Import-Module + _____ + CategoryInfo : ResourceExists: (Function:String) [Import-Module], ProviderInvocationException + FullyQualifiedErrorId : DriveAlreadyExists,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Module : A drive with the name 'Variable' already exists. + Import-Module + _____ + CategoryInfo : ResourceExists: (Variable:String) [Import-Module], ProviderInvocationException + FullyQualifiedErrorId : DriveAlreadyExists,Microsoft.PowerShell.Commands.ImportModuleCommand

Steps to reproduce behavior

Create Azure Function in version 1 In Azure Function place folder Modules/SharePointPnPPowershellOnline/{content-with-recent-module-version} Run Azure Function - during Import-Module you will see errors

Which version of the PnP-PowerShell Cmdlets are you using?

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

3.23.2007.1

How did you install the PnP-PowerShell Cmdlets?

Gayathrak80 commented 4 years ago

Hi, I got the same issue when using Azure Function in SharePoint site provisioning. For me I had another issue of where my AppID was expired and had to do this again. However I tried using the new PnP PowerShell version where still i got the same import module issue.

Not sure whether this will help but I tried to explicitly import the modules based on below reference https://www.nblabs.net/2018/06/27/azure-functions-import-module-and-drivealreadyexists/

It did work and executed the code to provision the site.

PRusakPL commented 4 years ago

Thank you @Gayathrak80 - your solution seems to be a workaround.