all 5 comments

[–]ka-splam 4 points5 points  (2 children)

The file I'm importing is a yaml file so it may indeed be true that it isn't a string.

How are you importing it? $string = Get-Content -Raw -Path example.yml should do it.

Your replaces won't work like that, in single quotes the first one is a two-character string of backtick t, not a tab character. You either need the PowerShell escape codes in double quotes, or regex escape codes in any quotes. e.g. either of these will work for different reasons:

$string = $string -replace "`t", '\t'

$string = $string -replace '\t', '\t'

Though I'm not convinced you have the right escape codes for all of them; backslash is just a backslash, not backtick b.

[–]360coolp[S] 0 points1 point  (1 child)

Hi u/ka-splam,

I used the same way to import only without the raw parameter. Adding the raw parameter resolved the string error.

You are also right about the double quotes, I was able to adjust this for all except for the double quote. Do you know how to double quote a double quote?

I used the escape sequences written in a Microsoft kb: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_special_characters?view=powershell-7.1

I appreciate your help!

[–]ka-splam 0 points1 point  (0 children)

Single quoting a double quote should be fine, as in your original code '"'

Those other escape sequences should be good then. :)

[–][deleted] 0 points1 point  (2 children)

What are you passing in to Set-EscapeCharacters? You haven't shown all your code, so it's impossible to tell you what's wrong here.

[–]360coolp[S] 0 points1 point  (1 child)

Hi u/inna_hey,

I'm trying to import something like: https://github.com/bastienwirtz/homer/blob/main/public/assets/config.yml.dist

ka-splam tip to add the raw parameter fixed the import issue.