-2

I have to invoke POST METHOD from powershell function which is having 8-9 parameters and these parameter may contain big strings.

I am calling powershell function from Azure DevOps Yaml based pipelines and We have a configuration YAML file which contains variables which need to be passed to POWERSHELL FUNCTION.

how to read these mulitple parameters from YAML file and pass it powershell script from YAML Based pipeline?Any relevant links or snippet will help.

I am very new to Powershell so I am sorry if question has not been put in correct way.

F11
  • 3,703
  • 12
  • 49
  • 83
  • 1
    You'd have to find a PowerShell module that converts yaml to json. Then use the convertto-json cmdlet to turn it into a PowerShell object. Then just create variables that point to the corresponding parameters your function is asking for. – Justin Beagley Feb 26 '23 at 03:16

1 Answers1

1

You need to install powershell-yaml module for that. Here is an example:

if (-not (Get-Module -ListAvailable -Name powershell-yaml)) {
    Install-Module powershell-yaml -Force
}

$yamlData = ConvertFrom-Yaml (Get-Content -Path .\data.yaml -Raw)

$yamlData is hashtable, so you can retrieve any object property from it.

For instance, if you have such content in yaml file:

name: DataObject
traits:
  - Green
  - Good
  - Round

value:
  dataArray:
    - FirstsPartOfData
    - SecondPartOfData

After reading you can access each property and array like this:

$yamlData.name
$yamlData.traits
$yamlData.value.dataArray
jdfa
  • 659
  • 4
  • 11