Azure DevOps error: The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell

Tzahi Kolber
4 min readAug 15, 2022

During one of my Azure DevOps projects, running YAML pipelines, I ran into an issue that appears to be quite common, but not so well documented within the web.

The issue

During the pipeline deployment, I got the following error:

“The current operating system is not capable of running this task. That typically means the task was written for Windows only. For example, written for Windows Desktop PowerShell”

The Reason for getting the error

The main reason for getting this error, is that the YAML task is configured to use PowerShell (Not Powershell Core!), while the Microsoft-hosted agent, which runs the task behind the scenes (unless you configure something else), is actually Ubuntu by default, when you run a YAML build pipeline:

“The default agent image for classic build pipelines is windows-2019, and the default agent image for YAML build pipelines is ubuntu-latest.

In this scenario, powershell runs Windows PowerShell and will ONLY work on a Windows agent!

PowerShell task — Azure Pipelines | Microsoft Docs

To review the hosted agent image, we can open the pipeline job and then under the Initialize job, Operating system, we can see that the image is running Ubuntu 20.04.4
In addition, under the Virtual Environment section, we can also see the same OS and version:

Solution

There 2 ways to handle and solve this error:

  1. Replace your YAML code to use CLI/pwsh instead of PowerShell.
    Of course, this solution is little bit more complicated and not applicable part of the time.

2. The second option is more simplified and easier to manage.
all you have to do, is just change the Azure Pipelines agent pool / Microsoft-hosted agent from Ubuntu to Windows.

By the way, in case you are using a Self-hosted agent, you can configure is as a Windows image as describes in the next article:
Deploy an Azure Pipelines agent on Windows — Azure Pipelines | Microsoft Docs

How to change it? very simple!

  • Pipelines:
    Just add the next lines in your YAML file:

pool:
vmImage: windows-latest

  • Release Pipelines:

Choose the Hosted Windows 2019 with VS2019 at the Agent Job / Agent Pool settings:

The YAML conversion to the release pipelines with the agent selected above, will look like this:

After adding and setting the hosted agent to Windows image, the pipeline runs without issues.
To verify the agent is running Windows image, we can open again the initialize job and review the Operating System and Virtual Environment sections:

HTH :-)

--

--

Tzahi Kolber

During the last 15 years, I was working as a Senior PFE within Exchange area at Microsoft. Now I’m Senior Consult as Azure IAAS, PowerShell & Automations.