What does @"String"@ syntax mean in powershell

Viewed 51

Not sure what this is an cant find it on the internet

$myString = @"
string
"@
$myRegularString = "string"

write-output $myString.getType() # outputs System.String
write-output $myRegularString.getType() # outputs System.String

I encountered the latter when someone converted the text of a string to a .pbk file. They originally said there was a problem converting it to utf8 but when I imported the .pbk properties from a text using get-content $myString -encoding utf8 file it was fine So whats the difference? Is one fancier?

1 Answers

Those are here-strings, they allow to preserve formatting, including line breaks:

$string = @"
this is
a test
string
"@

Also please be aware that when you use Get-Content -Path test.txt the result is an array of strings (each line is an array item). If you want to get the file content as a single string object you will need to use Get-Content -Path test.txt -Raw.

Related