Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Formatting Inline for Export-CliXML Command

Reply
 
Old 09-18-2007   #1 (permalink)
Brandon Shell


 
 

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
Quote:

> 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
Old 09-18-2007   #2 (permalink)
Glenn W.


 
 

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
Old 09-18-2007   #3 (permalink)
Brandon Shell


 
 

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
Quote:

> 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
Old 09-18-2007   #4 (permalink)
Glenn W.


 
 

Re: Formatting Inline for Export-CliXML Command

Thank you. Your help is much appreciated.

"Brandon Shell" wrote:
Quote:

> 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
Quote:

> > 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
Old 09-18-2007   #5 (permalink)
Shay Levi


 
 

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


Quote:

> 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>>
Quote:

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

>> 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
Old 09-18-2007   #6 (permalink)
Brandon Shell


 
 

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
Quote:

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

>> 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>>
Quote:

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

>>> 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
Old 09-18-2007   #7 (permalink)
Glenn W.


 
 

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:
Quote:

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

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

> >> 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>>
Quote:

> >> "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
Old 09-18-2007   #8 (permalink)
Brandon Shell


 
 

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
Quote:

> 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:
>
Quote:

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

>> > 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
Old 09-18-2007   #9 (permalink)
Shay Levi


 
 

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


Quote:

> 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:
>
Quote:

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

>>> 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
Old 09-18-2007   #10 (permalink)
Brandon Shell


 
 

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
Quote:

> 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:
>
Quote:

>> 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
Quote:

>> > 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
Reply

Thread Tools


Similar Threads
Thread Forum
Export-clixml producing weird xml output PowerShell
Export/Import-CliXml oddity PowerShell
export-clixml and compare-object question PowerShell
Export-Clixml output is inconvenient for viewing PowerShell
Export-CliXml/Export-Csv: Change to Export-Object? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46