I've got this line of code:
(Get-Content $path1 -Raw).Replace("`r`n","`n") | Set-Content $path1 -Forceand the -raw isn't recognized in v2... so my question is how can I use the above (which works get in v3) in v2?
Technology Tips and News
I've got this line of code:
(Get-Content $path1 -Raw).Replace("`r`n","`n") | Set-Content $path1 -Forceand the -raw isn't recognized in v2... so my question is how can I use the above (which works get in v3) in v2?
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
(Get-Content $path1 | Out-String).Replace("`r`n","`n") | Set-Content $path1 -Force
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
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
(Get-Content $path1 | Out-String).Replace("`r`n","`n") | Set-Content $path1 -Force
(Get-Content $path1 | Out-String).Replace("`r`n","`n") | Set-Content $path1 -Force