Share via

PnP.PowerShell Not Recognized in Azure Automation Runbook

Kaya Elif 20 Reputation points
2026-02-16T12:49:06.7933333+00:00

Hi everyone,

I’ve seen several similar issues reported, but none of the proposed solutions worked for me so far. Here is my situation.

I am using Azure Automation with a PowerShell 7.2 Runbook, and I am trying to run a very simple script: just connecting to a SharePoint Online site using PnP.PowerShell.

This is essentially the content of my Runbook:

Import-Module PnP.PowerShell -RequiredVersion 2.12.0
$cred = Get-AutomationPSCredential -Name 'Mon Test 1'
$ClientID_Source = "XXX"
$SiteSource = "https://XXX"
Connect-PnPOnline -Url $SiteSource -Credentials $cred -ClientId $ClientID_Source

I imported the PnP.PowerShell 2.12.0 ZIP file into the Azure Automation modules (Runtime 7.2). I know this version is the one supposed to work with Automation 7.2, which is why I used it.

I also installed the Microsoft.Online.SharePoint.PowerShell module (7.2 compatibility), just in case.

However, when I execute the Runbook, I consistently get the following errors:

Error 1 - ImportModule failure

Import-Module : The specified module 'PnP.PowerShell' with version '2.12.0' was not loaded because no valid module file was found in any module directory.

Error 2 - Cmdlet not found

Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file, or operable program.

So Azure Automation does not seem to load the module at all, even though it appears in the list of imported modules.

I would like to know:

  • if there is something specific required for Azure Automation to properly load the PnP.PowerShell 2.12.0 module,
  • if the ZIP structure must follow a particular format,
  • or if this is a known limitation / current issue with PowerShell 7.2 Runbooks.

Any help or clarification would be greatly appreciated.

Thank you :)

Azure Automation
Azure Automation

An Azure service that is used to automate, configure, and install updates across hybrid environments.

{count} votes

Answer accepted by question author
  1. Bharath Y P 5,800 Reputation points Microsoft External Staff Moderator
    2026-02-16T20:49:30.2466667+00:00

    Hello Kaya Elif, It looks like you’re having a tough time getting the PnP.PowerShell module to work in your Azure Automation Runbook. The errors you're encountering suggest that Azure isn't recognizing the module or cmdlets.

    To answer your question:

    1. Yes. There are two specific requirements that must be met.
    • Correct runtime alignment: PnP.PowerShell 2.12.0 is the last version officially compatible with Azure Automation PowerShell 7.2. Newer PnP versions (3.x) require PowerShell 7.4.6, which Azure Automation does not support yet in the legacy 7.2 runbook model. PnP’s own documentation explicitly states that 2.12.0 is the only stable version supported for Automation 7.2. If the runbook runtime is 7.2 and the module version is 2.12.0, the version compatibility is correct.
    • Module must be imported into the same runtime environment: If the module is imported into a different runtime environment than the runbook is using, PowerShell will fail. Microsoft Learn confirms that runtime environments are the execution boundary, and packages must exist inside the runtime linked to the runbook. This explains why modules can appear as Imported in the UI but still fail at runtime.
    1. Yes and this is the most common root cause of your exact error. Azure Automation follows PowerShell’s strict module discovery rules The ZIP must contain a single top-level folder named exactly the same as the module, and inside it the .psd1 must exist. If the ZIP instead contains PnP.PowerShell.2.12.0\Pnp.PowerShell...  and or only loose files without the PnP.PowerShell folder. Azure Automation will show the module as imported, but PowerShell cannot load it, producing exactly the error you see.
    2. Yes. this is a known and documented limitation. PowerShell 7.2 is deprecated upstream
      • Microsoft has officially stated that PowerShell 7.1 and 7.2 are no longer supported by the PowerShell product lifecycle.
      • Azure Automation still supports them for backward compatibility, but module ecosystem breakage is expected.
      Microsoft Learn explicitly recommends upgrading runbooks to PowerShell 7.4 Runtime Environments. https://learn.microsoft.com/en-us/azure/automation/quickstart-update-runbook-in-runtime-environment

    Hope this helps. Please let me know if you need any assistance. Thanks

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-16T12:49:25.6+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To resolve the issues you're experiencing with the PnP.PowerShell module in your Azure Automation Runbook, consider the following points:

    1. Module Import Issues: The error message indicating that the specified module could not be loaded suggests that the module might not be structured correctly or is not compatible with the Azure Automation environment. Ensure that the ZIP file you imported follows the correct structure, which typically includes a folder named after the module containing the module files. The correct structure should look like this:
         PnP.PowerShell
         ├── PnP.PowerShell.psd1
         ├── PnP.PowerShell.psm1
         └── (other necessary files)
      
    2. PowerShell 7.2 Limitations: There are known limitations when using PowerShell 7.x in Azure Automation. Specifically, ensure that the version of the PnP.PowerShell module you are using is compatible with the PowerShell 7.2 runtime. As of the latest updates, certain modules may not fully support the newer runtime versions.
    3. Module Availability: Verify that the PnP.PowerShell module is indeed imported into your Automation account. You can do this by checking the Modules section in the Azure portal. If the module is not listed or is outdated, you may need to re-import it.
    4. Cmdlet Recognition: The error stating that Connect-PnPOnline is not recognized indicates that the cmdlet is not available in the current context. This could be due to the module not loading properly. After ensuring the module is correctly structured and imported, try running a simple command like Get-Module to see if the PnP.PowerShell module is listed.
    5. Troubleshooting Steps: If the above steps do not resolve the issue, consider the following:
      • Test the script locally in a PowerShell 7.2 environment to confirm it works outside of Azure Automation.
      • Check for any conflicts with other modules that may be causing issues.
      • Ensure that your Azure Automation account has the necessary permissions to access the resources required by the PnP.PowerShell module.

    If these steps do not resolve your issue, you may want to consult the Azure documentation for further troubleshooting guidance specific to Azure Automation and PowerShell modules.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.