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] SharePointPnP.PowerShell.Online.Commands.dll was not loaded because no valid module file was found in any module directory #4736

Open
CrisCGTM opened this issue Feb 12, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@CrisCGTM
Copy link

CrisCGTM commented Feb 12, 2025

Starting form Jannuary 16, 2025, our release pipelines fail due to a PnP.PowerShell error because no valid module was found.

This is the output:

Starting: Connect to SharePoint and copy files
==============================================================================
Task         : Run PnP PowerShell
Description  : Can use PowerShell cmdlets inline or with a referenced script.
Version      : 3.0.4
Author       : Sebastian Schütze
Help         : This task helps you to execute inline PowerShell or a referenced file with the already loaded PnP PowerShell module. <br/><br/>[More Information](https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps)
==============================================================================
The script was partially inspired by the official Azure DevOps inline PowerShell task from Microsoft Corporation. Some lines are reused.
Source Code can be found here https://github.com/Microsoft/azure-pipelines-tasks/tree/e9f6da2c523e456f10421ed40dbeed1dd45af2b4/Tasks/powerShell
Module SharePointPnPPowerShellOnline with version 3.29.2101.0 is downloading.
##[error]The specified module 'C:\hostedtoolcache\windows\SharePointPnPPowerShellOnline\3.29.2101.0\SharePointPnP.PowerShell.Online.Commands.dll' was not loaded because no valid module file was found in any module directory.
Module Path is: C:\hostedtoolcache\windows\SharePointPnPPowerShellOnline\3.29.2101.0\SharePointPnP.PowerShell.Online.Commands.dll
Generating the scripts...
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\7ece8d4f-9e85-4189-bcaa-2c51617545ac.ps1'"
Import-Module : The specified module 
'C:\hostedtoolcache\windows\SharePointPnPPowerShellOnline\3.29.2101.0\SharePointPnP.PowerShell.Online.Commands.dll' 
was not loaded because no valid module file was found in any module directory.
At D:\a\_temp\7ece8d4f-9e85-4189-bcaa-2c51617545ac.ps1:2 char:9
+ $null = Import-Module C:\hostedtoolcache\windows\SharePointPnPPowerSh ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (C:\hostedtoolca...ne.Commands.dll:String) [Import-Module], FileNot 
   FoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
 
##[error]PowerShell exited with code: 1
Finishing: Connect to SharePoint and copy files

The pipeline target is connect to our SharePoint and upload some files.

Anybody has seen and solved this issue?
Any assistance would be greatly appreciated

@CrisCGTM CrisCGTM added the bug Something isn't working label Feb 12, 2025
@jackpoz
Copy link
Contributor

jackpoz commented Feb 12, 2025

3.29.2101.0 is the old version from https://github.com/pnp/PnP-PowerShell that has been archived, not updated since 2021 and no longer maintained. It's strongly recommended to migrated to PnP.PowerShell module .

@CrisCGTM
Copy link
Author

CrisCGTM commented Feb 13, 2025

This is really interesting because the pipeline is executed on Microsoft hosted VM and the pipeline's code worked fine in the last 2 years:

             - task: PnPPowerShell@3
              displayName: 'Connect to SharePoint and copy files'
              inputs:
                SharePointVersion: 'SpOnline'
                sharepointConntection: '$(SPServiceConnection)'
                FileOrInline: 'Inline'
                PnPPowerShellInline: |
                  $secpassword = ConvertTo-SecureString '$(SPPassword)' -AsPlainText -Force
                  $admincredentials = New-Object System.Management.Automation.PSCredential('$(SPUser)', $secpassword)
                  Connect-PnPOnline -Url '$(SPWebsiteURL_DEV)' -Credentials $admincredentials
                  $web = Get-PnPWeb
                  Write-Host "Connect to the url $($web.Url)"

                  Write-Host "Loading ZIP file into version root"
                  $filePath = '$(Pipeline.Workspace)\Build\UNITcc\$(UNITccAutoextrPrefix)$(FolderToDeploy).zip'
                  Write-Host "Copy File $($filePath) in $(SPDocLibURL_DEV)/$(SPFolderName_DEV)/$(ArtifactVersion)"
                  Add-PnPFile -Path "$($filePath)" -Folder "$(SPDocLibURL_DEV)/$(SPFolderName_DEV)/$(ArtifactVersion)"

                RequiredVersion: 'latest'

The required version is set to latest.
Any idea to migrate that code to best alternative?

@jackpoz
Copy link
Contributor

jackpoz commented Feb 13, 2025

SharePointPnPPowerShellOnline is the old module name, while the new one is PnP.PowerShell . That's why the "latest version" is still the 2021 one is your script.

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

2 participants