Rob Bowman
Rob Bowman

Reputation: 8741

Devops yaml "The term '-powershell:' is not recognized"

I'd like my devops build pipeline to run PowerShell that will list files it later complains it can't find.

When I run the following I get the error:

The term '-powershell:' is not recognized

Where did I go wrong?

name: Deploy Bicep files $(Build.BuildId)

trigger: none
# - main

variables:
  location: "uksouth"
  templateFile: "bicep/365Response.main.json"

pool:
  vmImage: "windows-latest"

stages:
  - stage: preDeploy
    variables:
      env: "dev"
    jobs:
      - job: listFiles
        displayName: List Files
        pool:
          vmImage: windows-2022

        steps:
          - task: PowerShell@2
            inputs:
              targetType: "inline"
              script: "-powershell: Get-ChildItem -Path '$(System.DefaultWorkingDirectory)' -recurse"

Upvotes: 1

Views: 478

Answers (2)

brc-dd
brc-dd

Reputation: 13074

You don't need to write -powershell: there.

Correct config:

        steps:
          - task: PowerShell@2
            inputs:
              targetType: "inline"
              script: "Get-ChildItem -Path '$(System.DefaultWorkingDirectory)' -recurse"

-powershell is actually a shortcut for the task. So you can also write this instead of the above:

        steps:
          - powershell: "Get-ChildItem -Path '$(System.DefaultWorkingDirectory)' -recurse"

Upvotes: 2

Seva Alekseyev
Seva Alekseyev

Reputation: 61396

The error message is from PowerShell, telling you that -powershell is not a valid construct in PowerShell :) And it's not.

To me, that says that inside the script element you need a valid powershell snippet, such as:

Get-ChildItem -Path '$(System.DefaultWorkingDirectory)' -recurse

Upvotes: 1

Related Questions