Powershell error related to 'Raw' parameter during Build pipeline execution

Copper Contributor

Hi Team,

I am facing below error during build where I am using powershell to read json file contents

Error: A parameter cannot be found that matches parameter name 'Raw'

 

Details:

in Azure build pipeline I have added Powershell task of version 2.* and its type 'File Path'

I have provided argument to powershell as  -path "System.DefaultWorkingDirectory\.......\*.json

-> In powershell file,

I have declared parameter as [string]$path 

I have written instruction as below

$json = (Get-Content -Path $path -Raw) | ConvertFrom-Json

and facing the error as "Error: A parameter cannot be found that matches parameter name 'Raw'" during powershell execution.

 

I tried many things to sort this out. Can anyone suggest your views/suggestions on this issue.

 

1 Reply

hi@Satyam569,

 1.while running the pipeline check the version of powershell, "Raw" parameter can be used for version3 ( https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?vie... ).

2.If in case powershell version is older then instead of Raw, you can use join or else update powershell version.

3. In my case what I did is as follows,

      i) Instead of writing get content command in file, write a one more powershell@2 task , type of inline script . 

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $FilePath = "path to file/jsoncontentfile.json" # Path 
      $figJson = (Get-Content $FilePath -Raw) | ConvertFrom-Json
    name: 'ConvertJSON'
    displayName: 'Convert Json '

  ii) define the variables in above script from json>can pass variable between tasks in same job>so pass those as arguments for file type powershell@2 task, as already it is there. and remove the get content code from script.ps1 file. 

I hope this is helpful 🙂