We created a Windows 2022 Data Centre Edition Scale Set set up as a Dev Ops agent pool yesterday.
I have an Agent Job that uses this agent pool. This job has a single inline Azure Powershell task.
Task Version: 5.*
Inline Script:
Write-Output "STUFF WORKS"
Azure Powershell Version: "Latest installed version
This gives me the error:
2023-01-13T10:15:17.6969002Z ##[error]Could not find the modules: 'Az.Accounts' with Version: ''. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
2023-01-13T10:15:19.3308359Z ##[error]PowerShell exited with code '1'.
with the whole stage output being:
2023-01-13T10:15:12.2607076Z ##[section]Starting: Test Task
2023-01-13T10:15:12.2806115Z ==============================================================================
2023-01-13T10:15:12.2806386Z Task : Azure PowerShell
2023-01-13T10:15:12.2806528Z Description : Run a PowerShell script within an Azure environment
2023-01-13T10:15:12.2806753Z Version : 5.209.0
2023-01-13T10:15:12.2806898Z Author : Microsoft Corporation
2023-01-13T10:15:12.2807054Z Help : https://aka.ms/azurepowershelltroubleshooting
2023-01-13T10:15:12.2807227Z ==============================================================================
2023-01-13T10:15:15.3504901Z Generating script.
2023-01-13T10:15:15.3776658Z ========================== Starting Command Output ===========================
2023-01-13T10:15:15.4059002Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\a\_temp\7baa15ed-a6fe-44a4-a586-ee2342cb9868.ps1'"
2023-01-13T10:15:17.0046974Z Added TLS 1.2 in session.
2023-01-13T10:15:17.6969002Z ##[error]Could not find the modules: 'Az.Accounts' with Version: ''. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
2023-01-13T10:15:19.3308359Z ##[error]PowerShell exited with code '1'.
2023-01-13T10:15:19.7131608Z Added TLS 1.2 in session.
2023-01-13T10:15:21.5490716Z ##[section]Finishing: Test Task
Any idea what I am doing wrong?
By my understanding the 2022 image already includes all of the expected modules so I've made no attempt to install them on the VM manually (something I would like to avoid)
Edit
It appears the behaviour of an Azure Powershell task for an Azure Pipeline Agent is different to a self hosted Scale Set Agent.
Azure Pipelines Output
2023-01-16T10:37:38.6306969Z ##[section]Starting: Azure PowerShell
2023-01-16T10:37:38.6580681Z ==============================================================================
2023-01-16T10:37:38.6581062Z Task : Azure PowerShell
2023-01-16T10:37:38.6581238Z Description : Run a PowerShell script within an Azure environment
2023-01-16T10:37:38.6581486Z Version : 5.209.0
2023-01-16T10:37:38.6581645Z Author : Microsoft Corporation
2023-01-16T10:37:38.6581853Z Help : https://aka.ms/azurepowershelltroubleshooting
2023-01-16T10:37:38.6582079Z ==============================================================================
2023-01-16T10:37:41.3655258Z Az version 8.3.0 not avaiable locally on the agent. Downloading dynamically.
2023-01-16T10:37:44.8252804Z
2023-01-16T10:37:44.8266994Z 7-Zip [64] 16.00 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-10
2023-01-16T10:37:44.8269675Z
2023-01-16T10:37:44.8270653Z Scanning the drive for archives:
2023-01-16T10:37:44.8271434Z 1 file, 67255559 bytes (65 MiB)
2023-01-16T10:37:44.8271762Z
2023-01-16T10:37:44.8273450Z Extracting archive: C:\Modules\az_8.3.0.zip
2023-01-16T10:38:01.5690462Z --
2023-01-16T10:38:01.5691333Z Path = C:\Modules\az_8.3.0.zip
2023-01-16T10:38:01.5691869Z Type = zip
2023-01-16T10:38:01.5692380Z Physical Size = 67255559
2023-01-16T10:38:01.5692646Z
2023-01-16T10:38:01.5737463Z Everything is Ok
2023-01-16T10:38:01.5738875Z
2023-01-16T10:38:01.5739352Z Folders: 81
2023-01-16T10:38:01.5739804Z Files: 1282
2023-01-16T10:38:01.5740267Z Size: 319427095
2023-01-16T10:38:01.5740807Z Compressed: 67255559
2023-01-16T10:38:01.6565020Z Generating script.
2023-01-16T10:38:01.7303016Z ========================== Starting Command Output ===========================
2023-01-16T10:38:01.7659410Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\500f8cc1-703a-4fd9-a989-b5dd273da179.ps1'"
2023-01-16T10:38:04.3997844Z Added TLS 1.2 in session.
2023-01-16T10:38:05.4501759Z ##[command]Import-Module -Name C:\Modules\az_8.3.0\Az.Accounts\2.10.0\Az.Accounts.psd1 -Global
2023-01-16T10:38:06.9713804Z WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the
2023-01-16T10:38:06.9716098Z same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can
2023-01-16T10:38:06.9716799Z use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure
2023-01-16T10:38:06.9717481Z Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found
2023-01-16T10:38:06.9721294Z here: https://aka.ms/azps-migration-guide
2023-01-16T10:38:11.2344046Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
2023-01-16T10:38:16.0123806Z ##[command]Clear-AzContext -Scope Process
2023-01-16T10:38:16.2401459Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant a76dcc71-5c97-4ed5-aa1f-0da680d1cac6 -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
2023-01-16T10:38:19.6273814Z ##[command] Set-AzContext -SubscriptionId 74fcd14b-fee9-4a50-9473-80759d0fd501 -TenantId a76dcc71-5c97-4ed5-aa1f-0da680d1cac6
2023-01-16T10:38:20.1588404Z Hello World!
2023-01-16T10:38:20.5851719Z Added TLS 1.2 in session.
2023-01-16T10:38:23.8606507Z ##[section]Finishing: Azure PowerShell
Self Hosted Scale Set
2023-01-16T10:31:31.7097135Z ##[section]Starting: Azure PowerShell
2023-01-16T10:31:31.7201130Z ==============================================================================
2023-01-16T10:31:31.7201358Z Task : Azure PowerShell
2023-01-16T10:31:31.7201494Z Description : Run a PowerShell script within an Azure environment
2023-01-16T10:31:31.7201678Z Version : 5.209.0
2023-01-16T10:31:31.7201792Z Author : Microsoft Corporation
2023-01-16T10:31:31.7201928Z Help : https://aka.ms/azurepowershelltroubleshooting
2023-01-16T10:31:31.7202096Z ==============================================================================
2023-01-16T10:31:33.1732716Z Generating script.
2023-01-16T10:31:33.1983231Z ========================== Starting Command Output ===========================
2023-01-16T10:31:33.2192281Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\a\_temp\4d87de77-f8f7-42fa-a3c9-b74c90364e48.ps1'"
2023-01-16T10:31:35.1895949Z Added TLS 1.2 in session.
2023-01-16T10:31:35.7608704Z ##[error]Could not find the modules: 'Az.Accounts' with Version: '8.3.0'. If the module was recently installed, retry after restarting the Azure Pipelines task agent.
2023-01-16T10:31:35.9925131Z ##[error]PowerShell exited with code '1'.
2023-01-16T10:31:36.1584011Z Added TLS 1.2 in session.
2023-01-16T10:31:37.3200590Z ##[section]Finishing: Azure PowerShell
Notice that the former makes an attempt to install Az via Extracting archive: C:\Modules\az_8.3.0.zip
where as the latter doesn't.