Windows Vista Forums

Get-content mess
  1. #1


    Chris Guest

    Get-content mess

    I have a text file formatted like so:

    ....
    Property1: Value1
    Property2: Value2
    Property3: Value3
    ....

    If I run the line "$a = get-content $file", is there anyway I can use
    the write-host cmdlet and retain the line breaks? Currently I get the
    following:



    Property1: Value1 Property2: Value2 Property3: Value3 ...


    Thanks,
    Chris

      My System SpecsSystem Spec

  2. #2


    Rob Campbell Guest

    RE: Get-content mess

    $a = get-content $file
    $a |% {write-host $_}

    "Chris" wrote:

    > I have a text file formatted like so:
    >
    > ....
    > Property1: Value1
    > Property2: Value2
    > Property3: Value3
    > ....
    >
    > If I run the line "$a = get-content $file", is there anyway I can use
    > the write-host cmdlet and retain the line breaks? Currently I get the
    > following:
    >
    > Property1: Value1 Property2: Value2 Property3: Value3 ...
    >
    >
    > Thanks,
    > Chris
    >

      My System SpecsSystem Spec

  3. #3


    Chris Guest

    Re: Get-content mess

    Good stuff, that'll do. Thanks again.


    On Feb 3, 12:22*pm, Rob Campbell
    <RobCampb...@xxxxxx> wrote:

    > $a = get-content $file
    > $a |% {write-host $_}
    >
    > "Chris" wrote:

    > > I have a text file formatted like so:
    >

    > > ....
    > > Property1: Value1
    > > Property2: Value2
    > > Property3: Value3
    > > ....
    >

    > > If I run the line "$a = get-content $file", is there anyway I can use
    > > the write-host cmdlet and retain the line breaks? *Currently I get the
    > > following:
    >

    > > Property1: Value1 Property2: Value2 Property3: Value3 ...
    >

    > > Thanks,
    > > Chris

      My System SpecsSystem Spec

  4. #4


    Keith Hill [MVP] Guest

    Re: Get-content mess

    Double check the type of $a, I'll bet it is:

    41> $a.GetType().Name
    Object[]

    Which is probably really an array of string:

    42> $a | %{$_.gettype().name}
    String
    String
    String
    String
    String

    My guess is that you observed the output of $a in one concatenated string by
    executing something like:

    "$a"

    If that is the case then PowerShell will use the value of $OFS (output field
    separator) to separate the elements of the array as it flattens them into
    the string. You could use $OFS="," for instance to get the whole array spit
    out as a single string where each element is comma separated. However if
    you want to maintain the line terminators then you can set
    $OFS=[Environment]::Newline.

    --
    Keith


    "Chris" <soulxflare@xxxxxx> wrote in message
    news:0d6b36bc-4814-437d-9ab5-18af590f9cef@xxxxxx

    > Good stuff, that'll do. Thanks again.
    >
    >
    > On Feb 3, 12:22 pm, Rob Campbell
    > <RobCampb...@xxxxxx> wrote:

    >> $a = get-content $file
    >> $a |% {write-host $_}
    >>
    >> "Chris" wrote:

    >> > I have a text file formatted like so:
    >>

    >> > ....
    >> > Property1: Value1
    >> > Property2: Value2
    >> > Property3: Value3
    >> > ....
    >>

    >> > If I run the line "$a = get-content $file", is there anyway I can use
    >> > the write-host cmdlet and retain the line breaks? Currently I get the
    >> > following:
    >>

    >> > Property1: Value1 Property2: Value2 Property3: Value3 ...
    >>

    >> > Thanks,
    >> > Chris
    >

      My System SpecsSystem Spec

Get-content mess problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Set-Content not updating file after get-content and forEach-Object Tolli PowerShell 1 14 Jun 2007
EMC and Microsoft Form New Enterprise Content Management Alliance, Extend Microsoft Office SharePoint Server With Content, Compliance and Archive Solutions z3r010 Vista News 0 03 Oct 2006
Issue: getting/setting variable content using Get/Set-Content =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 1 23 Sep 2006
Weirdness with get-content | replace | set-content - file content is deleted!! Andrew Watt [MVP] PowerShell 4 23 May 2006
The content type text/html of the response message does not match the content type of the binding (text/xml; charset=utf-8)." hazz Indigo 2 04 Mar 2006