Windows Vista Forums

Formatting Inline for Export-CliXML Command
  1. #1


    Brandon Shell Guest

    Re: Formatting Inline for Export-CliXML Command

    Two things...
    First.. you dont want to use select.. use foreach-object
    $log | foreach-object{$_.Message -replace "'", ""} | export-clixml

    Second.. you can try WMI object to see if parses in XML better
    PS> Get-WmiObject Win32_NTLogEventLog

    "Glenn W." <Glenn W.@xxxxxx> wrote in message
    news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx

    > Hello,
    >
    > I am trying to export the event log to a sql database and in doing so, I
    > exporting the eventLog as an XML string and passing it into a stored
    > procedure which will parse.
    >
    > My trouble is that the messages contain apostrophes which of course SQL
    > doesn't like and I was curious as to how I would go about escaping them in
    > line as I export the data.
    >
    > Something like:
    > $log = get-eventlog -list
    > $log = $log[0].Entries
    >
    > $log | select message -replace "'", "" | export-clixml
    >
    > Of course, unfortunately that doesn't work. Does anyone have any
    > suggestions? Thanks in advance.



      My System SpecsSystem Spec

  2. #2


    Glenn W. Guest

    Formatting Inline for Export-CliXML Command

    Hello,

    I am trying to export the event log to a sql database and in doing so, I
    exporting the eventLog as an XML string and passing it into a stored
    procedure which will parse.

    My trouble is that the messages contain apostrophes which of course SQL
    doesn't like and I was curious as to how I would go about escaping them in
    line as I export the data.

    Something like:
    $log = get-eventlog -list
    $log = $log[0].Entries

    $log | select message -replace "'", "" | export-clixml

    Of course, unfortunately that doesn't work. Does anyone have any
    suggestions? Thanks in advance.

      My System SpecsSystem Spec

  3. #3


    Brandon Shell Guest

    Re: Formatting Inline for Export-CliXML Command

    You may find these interesting in regards to select object
    http://bsonposh.com/modules/wordpress/?p=25
    and
    http://bsonposh.com/modules/wordpress/?p=26

    "Glenn W." <Glenn W.@xxxxxx> wrote in message
    news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx

    > Hello,
    >
    > I am trying to export the event log to a sql database and in doing so, I
    > exporting the eventLog as an XML string and passing it into a stored
    > procedure which will parse.
    >
    > My trouble is that the messages contain apostrophes which of course SQL
    > doesn't like and I was curious as to how I would go about escaping them in
    > line as I export the data.
    >
    > Something like:
    > $log = get-eventlog -list
    > $log = $log[0].Entries
    >
    > $log | select message -replace "'", "" | export-clixml
    >
    > Of course, unfortunately that doesn't work. Does anyone have any
    > suggestions? Thanks in advance.

      My System SpecsSystem Spec

  4. #4


    Glenn W. Guest

    Re: Formatting Inline for Export-CliXML Command

    Thank you. Your help is much appreciated.

    "Brandon Shell" wrote:

    > You may find these interesting in regards to select object
    > http://bsonposh.com/modules/wordpress/?p=25
    > and
    > http://bsonposh.com/modules/wordpress/?p=26
    >
    > "Glenn W." <Glenn W.@xxxxxx> wrote in message
    > news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx

    > > Hello,
    > >
    > > I am trying to export the event log to a sql database and in doing so, I
    > > exporting the eventLog as an XML string and passing it into a stored
    > > procedure which will parse.
    > >
    > > My trouble is that the messages contain apostrophes which of course SQL
    > > doesn't like and I was curious as to how I would go about escaping them in
    > > line as I export the data.
    > >
    > > Something like:
    > > $log = get-eventlog -list
    > > $log = $log[0].Entries
    > >
    > > $log | select message -replace "'", "" | export-clixml
    > >
    > > Of course, unfortunately that doesn't work. Does anyone have any
    > > suggestions? Thanks in advance.
    >
    >

      My System SpecsSystem Spec

  5. #5


    Shay Levi Guest

    Re: Formatting Inline for Export-CliXML Command

    Still, you can do it with select :

    select @{name="message";expression={$_.message -replace "'", ""}}



    Shay
    http://scriptolog.blogspot.com



    > Two things...
    > First.. you dont want to use select.. use foreach-object
    > $log | foreach-object{$_.Message -replace "'", ""} | export-clixml
    > Second.. you can try WMI object to see if parses in XML better
    >
    PS>> Get-WmiObject Win32_NTLogEventLog
    PS>>

    > "Glenn W." <Glenn W.@xxxxxx> wrote in message
    > news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx
    >

    >> Hello,
    >>
    >> I am trying to export the event log to a sql database and in doing
    >> so, I exporting the eventLog as an XML string and passing it into a
    >> stored procedure which will parse.
    >>
    >> My trouble is that the messages contain apostrophes which of course
    >> SQL doesn't like and I was curious as to how I would go about
    >> escaping them in line as I export the data.
    >>
    >> Something like:
    >> $log = get-eventlog -list
    >> $log = $log[0].Entries
    >> $log | select message -replace "'", "" | export-clixml
    >>
    >> Of course, unfortunately that doesn't work. Does anyone have any
    >> suggestions? Thanks in advance.
    >>


      My System SpecsSystem Spec

  6. #6


    Brandon Shell Guest

    Re: Formatting Inline for Export-CliXML Command

    Then you lose the rest of the object You will only get the message

    "Shay Levi" <no@xxxxxx> wrote in message
    news:8766a94477d48c9c82b986b7656@xxxxxx

    > Still, you can do it with select :
    >
    > select @{name="message";expression={$_.message -replace "'", ""}}
    >
    >
    >
    > Shay
    > http://scriptolog.blogspot.com
    >
    >
    >

    >> Two things...
    >> First.. you dont want to use select.. use foreach-object
    >> $log | foreach-object{$_.Message -replace "'", ""} | export-clixml
    >> Second.. you can try WMI object to see if parses in XML better
    >>
    > PS>> Get-WmiObject Win32_NTLogEventLog
    > PS>>

    >> "Glenn W." <Glenn W.@xxxxxx> wrote in message
    >> news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx
    >>

    >>> Hello,
    >>>
    >>> I am trying to export the event log to a sql database and in doing
    >>> so, I exporting the eventLog as an XML string and passing it into a
    >>> stored procedure which will parse.
    >>>
    >>> My trouble is that the messages contain apostrophes which of course
    >>> SQL doesn't like and I was curious as to how I would go about
    >>> escaping them in line as I export the data.
    >>>
    >>> Something like:
    >>> $log = get-eventlog -list
    >>> $log = $log[0].Entries
    >>> $log | select message -replace "'", "" | export-clixml
    >>>
    >>> Of course, unfortunately that doesn't work. Does anyone have any
    >>> suggestions? Thanks in advance.
    >>>
    >
    >

      My System SpecsSystem Spec

  7. #7


    Glenn W. Guest

    Re: Formatting Inline for Export-CliXML Command

    That's the issue I was having. I'm trying to collect all the information
    from the event log entry, but edit the message so as to remove the characters
    that will "piss off" SQL such as apostrophes and what not.

    Unfortunately, with the WMI object I was having the same issues with being
    unable to edit the message in line.

    "Brandon Shell" wrote:

    > Then you lose the rest of the object You will only get the message
    >
    > "Shay Levi" <no@xxxxxx> wrote in message
    > news:8766a94477d48c9c82b986b7656@xxxxxx

    > > Still, you can do it with select :
    > >
    > > select @{name="message";expression={$_.message -replace "'", ""}}
    > >
    > >
    > >
    > > Shay
    > > http://scriptolog.blogspot.com
    > >
    > >
    > >

    > >> Two things...
    > >> First.. you dont want to use select.. use foreach-object
    > >> $log | foreach-object{$_.Message -replace "'", ""} | export-clixml
    > >> Second.. you can try WMI object to see if parses in XML better
    > >>
    > > PS>> Get-WmiObject Win32_NTLogEventLog
    > > PS>>

    > >> "Glenn W." <Glenn W.@xxxxxx> wrote in message
    > >> news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx
    > >>
    > >>> Hello,
    > >>>
    > >>> I am trying to export the event log to a sql database and in doing
    > >>> so, I exporting the eventLog as an XML string and passing it into a
    > >>> stored procedure which will parse.
    > >>>
    > >>> My trouble is that the messages contain apostrophes which of course
    > >>> SQL doesn't like and I was curious as to how I would go about
    > >>> escaping them in line as I export the data.
    > >>>
    > >>> Something like:
    > >>> $log = get-eventlog -list
    > >>> $log = $log[0].Entries
    > >>> $log | select message -replace "'", "" | export-clixml
    > >>>
    > >>> Of course, unfortunately that doesn't work. Does anyone have any
    > >>> suggestions? Thanks in advance.
    > >>>
    > >
    > >
    >
    >

      My System SpecsSystem Spec

  8. #8


    Brandon Shell Guest

    Re: Formatting Inline for Export-CliXML Command

    But the foreach helped correct?

    $log | foreach-object{$_.Message -replace "'", ""} | export-clixml

    "Glenn W." <GlennW@xxxxxx> wrote in message
    news:BBC2B90C-B4C4-4F1B-BF25-93870AA7FDA6@xxxxxx

    > That's the issue I was having. I'm trying to collect all the information
    > from the event log entry, but edit the message so as to remove the
    > characters
    > that will "piss off" SQL such as apostrophes and what not.
    >
    > Unfortunately, with the WMI object I was having the same issues with being
    > unable to edit the message in line.
    >
    > "Brandon Shell" wrote:
    >

    >> Then you lose the rest of the object You will only get the message
    >>
    >> "Shay Levi" <no@xxxxxx> wrote in message
    >> news:8766a94477d48c9c82b986b7656@xxxxxx

    >> > Still, you can do it with select :
    >> >
    >> > select @{name="message";expression={$_.message -replace "'", ""}}
    >> >
    >> >
    >> >
    >> > Shay
    >> > http://scriptolog.blogspot.com
    >> >
    >> >
    >> >
    >> >> Two things...
    >> >> First.. you dont want to use select.. use foreach-object
    >> >> $log | foreach-object{$_.Message -replace "'", ""} | export-clixml
    >> >> Second.. you can try WMI object to see if parses in XML better
    >> >>
    >> > PS>> Get-WmiObject Win32_NTLogEventLog
    >> > PS>>
    >> >> "Glenn W." <Glenn W.@xxxxxx> wrote in message
    >> >> news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx
    >> >>
    >> >>> Hello,
    >> >>>
    >> >>> I am trying to export the event log to a sql database and in doing
    >> >>> so, I exporting the eventLog as an XML string and passing it into a
    >> >>> stored procedure which will parse.
    >> >>>
    >> >>> My trouble is that the messages contain apostrophes which of course
    >> >>> SQL doesn't like and I was curious as to how I would go about
    >> >>> escaping them in line as I export the data.
    >> >>>
    >> >>> Something like:
    >> >>> $log = get-eventlog -list
    >> >>> $log = $log[0].Entries
    >> >>> $log | select message -replace "'", "" | export-clixml
    >> >>>
    >> >>> Of course, unfortunately that doesn't work. Does anyone have any
    >> >>> suggestions? Thanks in advance.
    >> >>>
    >> >
    >> >
    >>
    >>

      My System SpecsSystem Spec

  9. #9


    Shay Levi Guest

    Re: Formatting Inline for Export-CliXML Command

    Suggestion. Wouldn't it be great if SQL could have a column of a "Here-String"
    type?



    Shay
    http://scriptolog.blogspot.com



    > That's the issue I was having. I'm trying to collect all the
    > information from the event log entry, but edit the message so as to
    > remove the characters that will "piss off" SQL such as apostrophes and
    > what not.
    >
    > Unfortunately, with the WMI object I was having the same issues with
    > being unable to edit the message in line.
    >
    > "Brandon Shell" wrote:
    >

    >> Then you lose the rest of the object You will only get the message
    >>
    >> "Shay Levi" <no@xxxxxx> wrote in message
    >> news:8766a94477d48c9c82b986b7656@xxxxxx
    >>

    >>> Still, you can do it with select :
    >>>
    >>> select @{name="message";expression={$_.message -replace "'", ""}}
    >>>
    >>> Shay
    >>> http://scriptolog.blogspot.com
    >>>> Two things...
    >>>> First.. you dont want to use select.. use foreach-object
    >>>> $log | foreach-object{$_.Message -replace "'", ""} | export-clixml
    >>>> Second.. you can try WMI object to see if parses in XML better
    >>> PS>> Get-WmiObject Win32_NTLogEventLog
    >>> PS>>
    >>>> "Glenn W." <Glenn W.@xxxxxx> wrote in message
    >>>> news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx
    >>>>
    >>>>> Hello,
    >>>>>
    >>>>> I am trying to export the event log to a sql database and in doing
    >>>>> so, I exporting the eventLog as an XML string and passing it into
    >>>>> a stored procedure which will parse.
    >>>>>
    >>>>> My trouble is that the messages contain apostrophes which of
    >>>>> course SQL doesn't like and I was curious as to how I would go
    >>>>> about escaping them in line as I export the data.
    >>>>>
    >>>>> Something like:
    >>>>> $log = get-eventlog -list
    >>>>> $log = $log[0].Entries
    >>>>> $log | select message -replace "'", "" | export-clixml
    >>>>> Of course, unfortunately that doesn't work. Does anyone have any
    >>>>> suggestions? Thanks in advance.
    >>>>>


      My System SpecsSystem Spec

  10. #10


    Brandon Shell Guest

    Re: Formatting Inline for Export-CliXML Command

    Maybe a different approach

    $log | export-clixml $temp
    $temp -replace "'","" | out-file $file

    "Glenn W." <GlennW@xxxxxx> wrote in message
    news:681D2EF1-5D41-498A-A4B5-7604CEB0F4F2@xxxxxx

    > The foreach did help, yes, but I had brain farts with applying that to
    > other
    > columns.
    >
    > I attempted a:
    >
    > $log | foreach {$_.eventId $_.message -replace "'", ""} | export-clixml
    >
    > and understandably I got an error trying to do that because it doesn't
    > know
    > what to do with those two columns. Sorry for being slow. It's been one
    > of
    > those days today.
    >
    > "Brandon Shell" wrote:
    >

    >> But the foreach helped correct?
    >>
    >> $log | foreach-object{$_.Message -replace "'", ""} | export-clixml
    >>
    >> "Glenn W." <GlennW@xxxxxx> wrote in message
    >> news:BBC2B90C-B4C4-4F1B-BF25-93870AA7FDA6@xxxxxx

    >> > That's the issue I was having. I'm trying to collect all the
    >> > information
    >> > from the event log entry, but edit the message so as to remove the
    >> > characters
    >> > that will "piss off" SQL such as apostrophes and what not.
    >> >
    >> > Unfortunately, with the WMI object I was having the same issues with
    >> > being
    >> > unable to edit the message in line.
    >> >
    >> > "Brandon Shell" wrote:
    >> >
    >> >> Then you lose the rest of the object You will only get the message
    >> >>
    >> >> "Shay Levi" <no@xxxxxx> wrote in message
    >> >> news:8766a94477d48c9c82b986b7656@xxxxxx
    >> >> > Still, you can do it with select :
    >> >> >
    >> >> > select @{name="message";expression={$_.message -replace "'", ""}}
    >> >> >
    >> >> >
    >> >> >
    >> >> > Shay
    >> >> > http://scriptolog.blogspot.com
    >> >> >
    >> >> >
    >> >> >
    >> >> >> Two things...
    >> >> >> First.. you dont want to use select.. use foreach-object
    >> >> >> $log | foreach-object{$_.Message -replace "'", ""} | export-clixml
    >> >> >> Second.. you can try WMI object to see if parses in XML better
    >> >> >>
    >> >> > PS>> Get-WmiObject Win32_NTLogEventLog
    >> >> > PS>>
    >> >> >> "Glenn W." <Glenn W.@xxxxxx> wrote in message
    >> >> >> news:BEE4D31B-A4A2-4214-B70A-096F589BAEBC@xxxxxx
    >> >> >>
    >> >> >>> Hello,
    >> >> >>>
    >> >> >>> I am trying to export the event log to a sql database and in doing
    >> >> >>> so, I exporting the eventLog as an XML string and passing it into
    >> >> >>> a
    >> >> >>> stored procedure which will parse.
    >> >> >>>
    >> >> >>> My trouble is that the messages contain apostrophes which of
    >> >> >>> course
    >> >> >>> SQL doesn't like and I was curious as to how I would go about
    >> >> >>> escaping them in line as I export the data.
    >> >> >>>
    >> >> >>> Something like:
    >> >> >>> $log = get-eventlog -list
    >> >> >>> $log = $log[0].Entries
    >> >> >>> $log | select message -replace "'", "" | export-clixml
    >> >> >>>
    >> >> >>> Of course, unfortunately that doesn't work. Does anyone have any
    >> >> >>> suggestions? Thanks in advance.
    >> >> >>>
    >> >> >
    >> >> >
    >> >>
    >> >>
    >>
    >>

      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
Formatting Inline for Export-CliXML Command problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export-clixml producing weird xml output j-n-b PowerShell 2 30 Mar 2009
Export/Import-CliXml oddity Keith Hill PowerShell 1 11 Feb 2007
export-clixml and compare-object question Gaurhoth PowerShell 1 21 Dec 2006
Export-Clixml output is inconvenient for viewing =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 3 05 Sep 2006
Export-CliXml/Export-Csv: Change to Export-Object? Alex K. Angelopoulos [MVP] PowerShell 3 04 Jun 2006