YamlDotNet and powershell-yaml cmdlet gives error after conversion and unable to modify yml file as expected RRS feed

  • Question

  • I have main.yml file I want to append applications name My-APP to MY-APP.xml and Blue-App to Blue-App.xml

    I am referring executing below code, there is no error after execution but at final I am not getting $PsArray in correct .yml format

    After execution it gives an error

    New-Object YamlDotNet.Serialization.Serializer assembly could not loaded

    I have added Add-type assembly name still not getting final .yml file with application name

    change status, the error continues

    Install-Module -Name powershell-yaml -Force -Repository PSGallery -Scope CurrentUser
    install-package -name YamlDotNet
    $RawYaml = get-content c:\temp\main.yml
    # Convert YAML to PowerShell Object
    $PsYaml = (ConvertFrom-Yaml -Yaml $RawYaml)
    # Convert the Object to JSON
    $PsJson = @($PsYaml | ConvertTo-Json)
    # Convert JSON back to PowerShell Array
    $PsArray = @($PsJson | ConvertFrom-Json)
    # Convert the Array to YAML
    ConvertTo-Yaml -Data $PsArray

    main.yml file below 

    --- applications: - name: MY-APP

    -name: Blue-APP

      check-interval: 5s
      default-executor: jmeter

    provisioning: local

    • Edited by Himanshu_Kulkarni Monday, August 19, 2019 7:22 PM formatting code
    • Moved by jrv Wednesday, August 21, 2019 7:03 AM abandoned
    Monday, August 19, 2019 7:20 PM

All replies

  • Please ask the author of the script for help. We do t support scripts found on the Internet.

    Forum Posting Guidelines


    Monday, August 19, 2019 7:34 PM
  • I have done workaround here, treating file as text and its done but not sure for more complex yml files, if Microsoft can fine tune built in cmdlets similar to convertto-json or convertfrom-json then it will be very helpful

    $con=(gc $a )-join "`r`n"
    foreach ($i in $con)
      if ($i.indexof("name: "))
        $substr= $i.replace($i,"$i.xml")
         $substr= $i
    $out=$out+$substr | out-file $a

    Wednesday, August 21, 2019 4:12 AM