1

According to my last question Compare two Files I finally mentioned to get all to work inside my .bat. Thanks again for all the support.

However, as I find out today my supervisor is using Powershell in Version 2 instead of 5.1 than I do. The problem now is that the -Raw paramterer of this code:

$target = Get-Content "C:/pbr_tmp/PBreport/trc/TlsTrace.prn" -Raw is not recognized.

Is there some alternative implementation instead of using -Raw?

Pupose of -Raw: The commands in this example get the contents of a file as one string, instead of an array of strings.

I am not sure If an upgrade from PS2 to PS5.1 is possible.

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
SRel
  • 383
  • 1
  • 11

1 Answers1

1

When using PowerShell version 2 you can use

 $target = [System.IO.File]::ReadAllText("C:/pbr_tmp/PBreport/trc/TlsTrace.prn")

From SS64:

-Raw Return multiple lines as a single string (PowerShell 3.0)

In PowerShell 2.0 use the static method: [System.IO.File]::ReadAllText(string path)

Bassie
  • 9,529
  • 8
  • 68
  • 159
  • perfect that worked fine. However there are nwo some other lines which seems not be working correctly. I maybe have to completely switch Do you see any command which can cause problems in PS2? – SRel May 26 '20 at 15:51
  • @SRel Glad to hear it helped. You should mark this as answer and then please post a separate question for your other issue. If you send me the link I will try to help! – Bassie May 26 '20 at 15:54
  • Thanks @Bassie I asked a new one here: https://stackoverflow.com/questions/62026711/conversion-from-powershell-v5-to-powershell-v2 – SRel May 26 '20 at 16:18