After you use a self-hosted agent for Windows, Make sure you have referenced windows as a host pool in your YAML pipeline. Also, If you’re using the azure PowerShell task, Make sure you have installed the Powershell module in your VM acting as a self-hosted agent.
I created one windows VM (Windows Server 2019 Datacenter Gen2) in Azure Portal and authorized it to work as a self-hosted agent in Azure DevOps with the PAT token like below:-


Self hosted agent is online in Azure DevOps:-
Note- It is a part of Default Pool in my Azure DevOps org

Now, I ran an Azure-Powershell inline script with this Agent in Azure DevOps :-
Yaml pipeline code:-
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- main
pool:
name: Default
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: AzurePowerShell@5
inputs:
azureSubscription: 'SID subscription(xxxxxx365-f598-44d6-xxxx-e2b6e97cb2a7)'
ScriptType: 'InlineScript'
Inline: 'Get-AzResource | Format-Table'
azurePowerShellVersion: 'LatestVersion'
Note:- I have added pool as Default where my agent pool is connected
in Azure DevOps, Make sure you use the correct pool here in your YAML
code:-
pool:
name: Default
The Azure Powershell script ran successfully like below:-

Now, when I ran another SQL Inline script with my pool set to another agent OR ubuntu-image, I got same error code as yours:-
trigger:
- main
pool:
vmImage: ubuntu-latest
Pipeline Output:-

When I changed the pool to windows, the error was resolved and the task ran successfully like below:-
trigger:
- main
pool:
vmImage: windows-latest
Pipeline Output:-

Make sure you’re selecting the correct pool and the Powershell module is installed properly inside that VM which is acting as an Azure DevOps agent.
Reference:-
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. – AzureFileCopy@4 | What I Broke – Programming and Web Development