Using PS v3 command in PS v2

I've got this line of code:

(Get-Content $path1 -Raw).Replace("`r`n","`n") | Set-Content $path1 -Force
and the -raw isn't recognized in v2... so my question is how can I use the above (which works get in v3) in v2?

July 9th, 2015 6:15am

Raw parameter in Powershell V3  ignores newline characters and returns the entire contents of a file in one string. 

Similar to this, we have ReadAllText(a static method) in [System.IO.File] , which does the same thing. 

So you can use

([System.IO.File]::ReadAllText("$path1")).Replace("`r`n","`n") | Set-Content $path1 -Force

in Powershell V2.
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 7:51am

(Get-Content $path1 | Out-String).Replace("`r`n","`n") | Set-Content $path1 -Force



July 9th, 2015 7:54am

Thank You!
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 8:45am

Raw parameter in Powershell V3  ignores newline characters and returns the entire contents of a file in one string. 

Similar to this, we have ReadAllText(a static method) in [System.IO.File] , which does the same thing. 

So you can use

([System.IO.File]::ReadAllText("$path1")).Replace("`r`n","`n") | Set-Content $path1 -Force

in Powershell V2.
July 9th, 2015 11:47am

Raw parameter in Powershell V3  ignores newline characters and returns the entire contents of a file in one string. 

Similar to this, we have ReadAllText(a static method) in [System.IO.File] , which does the same thing. 

So you can use

([System.IO.File]::ReadAllText("$path1")).Replace("`r`n","`n") | Set-Content $path1 -Force

in Powershell V2.
Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 11:47am

(Get-Content $path1 | Out-String).Replace("`r`n","`n") | Set-Content $path1 -Force



July 9th, 2015 11:50am

(Get-Content $path1 | Out-String).Replace("`r`n","`n") | Set-Content $path1 -Force



Free Windows Admin Tool Kit Click here and download it now
July 9th, 2015 11:50am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics