Hello Jan Duchač
Firstly, PnP.PowerShell versions beyond 2.x require PowerShell 7.4+, but Azure Automation currently supports only PowerShell 5.1 and 7.2. This mismatch causes cmdlets to fail even if the module appears imported.
So, to resolve this issue follow the below workaround.
- Go to the runtime environment you are using.
- Delete any broken PnP.PowerShell module from your Automation account using Portal or:
Remove-AzAutomationModule -Name "PnP.PowerShell" -ResourceGroupName <RG> -AutomationAccountName <AA> -Force
- Go to the PowerShell Gallery to the page of the latest working module version (in your case 2.12): https://www.powershellgallery.com/packages/PnP.PowerShell/2.12.0
- Rename the downloaded
.nupkg
toPnP.PowerShell.zip
- In Azure Portal, under your Automation Account → Modules → Add a module:
- Choose + Add a file.
- Upload your
PnP.PowerShell.zip
. - Wait—import can take up to 10 minutes—then verify the module shows as Available
- Once imported, use:
This should load the module and make its cmdlets available in your runbookImport-Module -Name PnP.PowerShell -RequiredVersion 2.12.0
You can refer the similar issue : https://learn.microsoft.com/en-us/answers/questions/2265480/import-pnponline-error-in-azure-automation-runbook?utm_source=chatgpt.com
If the provided solution helpful for your query, please click Upvote it.
Thanks