View Single Post
Old 09-22-2006   #8 (permalink)
Lee Holmes [MSFT]


 
 

Re: Why does get-content on a text file remove crlf when cast to a string?

There is often a distinction, but usually there is not. We designed
PowerShell to allow you to smoothly glide between typical scripting tasks
and more complex programming tasks -- our support for .Net being a key to
this spectacular amount of breadth.

For example, PowerShell will likely not ever support random I/O on a file
stream. That's a task that the .Net framework handles well, using a model
that customers are familiar with. It doesn't make much sense for PowerShell
to re-implement all of that, just as there will always be sections of the
Win32 API that .Net users need to call through P/Invoke techniques.

As you move away from goals obviously covered by language primitives and
stock cmdlets, there comes a point where it just makes sense to get on the
powerful bridge of .Net interop. In this specific case, the ReadAllText()
method on [System.IO.File] really is the best solution for PowerShell V1.

(This is actually an option that we hope to add to Get-Content in the
future, though)

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Mark" <mwatts at hotmail dot com> wrote in message
news:E6BEC1EF-F8CA-45A0-A9B6-4110D28FA7E5@microsoft.com...
> "XShell" <xshell@nospam.com> wrote in message
> news:ehbHZ3D3GHA.4756@TK2MSFTNGP04.phx.gbl...
>>>>
>>>> gci -i Assemblyinfo.cs -r | %{$contents=gc
>>>> $_.FullName;doWork([system.string]::join("`r`n", $contents)) }
>>>>

>>
>> or you can use .Net
>>
>> [System.IO.File]::ReadAllText(Assemblyinfo.cs)

>
> Actually that was what I did while waiting for the answer to my newsgroup
> question. But while that it the ".NET way" it is not the "PowerShell
> Way".
>
>
>



My System SpecsSystem Spec