Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating an RSS feed from PowerShell

417 views
Skip to first unread message

Mark Wilson

unread,
Aug 22, 2007, 7:42:01 PM8/22/07
to
I'm just learning PowerShell but one of the examples I saw today
involved reading an event log and filtering the results. It struck me
that if I could then export this as RSS (using export-clixml) then I
could have administrators subscribe to a feed which published
important events.

This sounds fine, except that the XML produced by export-clixml is not
RSS. Does anyone know how I can convert it (or can anyone offer any
advice?).

TIA, Mark

Keith Hill [MVP]

unread,
Aug 22, 2007, 9:40:48 PM8/22/07
to
ÿþ< ! D O C T Y P E H T M L P U B L I C " - / / W 3 C / / D T D H T M L 4 . 0 T r a n s i t i o n a l / / E N " > < H T M L > < H E A D > < M E T A h t t p - e q u i v = C o n t e n t - T y p e c o n t e n t = " t e x t / h t m l ; c h a r s e t = u n i c o d e " > < M E T A c o n t e n t = " M S H T M L 6 . 0 0 . 6 0 0 0 . 1 6 4 8 1 " n a m e = G E N E R A T O R > < / H E A D > < B O D Y i d = M a i l C o n t a i n e r B o d y s t y l e = " P A D D I N G - R I G H T : 1 0 p x ; P A D D I N G - L E F T : 1 0 p x ; F O N T - S I Z E : 1 0 p t ; C O L O R : # 0 0 0 0 0 0 ; P A D D I N G - T O P : 1 5 p x ; F O N T - F A M I L Y : A r i a l " b g C o l o r = # f f f f f f l e f t M a r g i n = 0 t o p M a r g i n = 0 C a n v a s T a b S t o p = " t r u e " n a m e = " C o m p o s e m e s s a g e a r e a " a c c _ r o l e = " t e x t " > " M a r k W i l s o n " & l t ; m a r k w @ m a r k w i l s o n . c o . u k & g t ; w r o t e i n m e s s a g e n e w s : 1 1 8 7 8 2 6 1 2 1 . 6 9 4 9 6 7 . 1 2 2 3 8 0 @ r 2 3 g 2 0 0 0 p r d . g o o g l e g r o u p s . c o m . . . < B R > & g t ; I ' m j u s t l e a r n i n g P o w e r S h e l l b u t o n e o f t h e e x a m p l e s I s a w t o d a y < B R > & g t ; i n v o l v e d r e a d i n g a n e v e n t l o g a n d f i l t e r i n g t h e r e s u l t s . & n b s p ; I t s t r u c k m e < B R > & g t ; t h a t i f I c o u l d t h e n e x p o r t t h i s a s R S S ( u s i n g e x p o r t - c l i x m l ) t h e n I < B R > & g t ; c o u l d h a v e a d m i n i s t r a t o r s s u b s c r i b e t o a f e e d w h i c h p u b l i s h e d < B R > & g t ; i m p o r t a n t e v e n t s . < B R > & g t ; < B R > & g t ; T h i s s o u n d s f i n e , e x c e p t t h a t t h e X M L p r o d u c e d b y e x p o r t - c l i x m l i s n o t < B R > & g t ; R S S . & n b s p ; D o e s a n y o n e k n o w h o w I c a n c o n v e r t i t ( o r c a n a n y o n e o f f e r a n y < B R > & g t ; a d v i c e ? ) . < B R > < B R > T r y t h i s - n o t e i t o n l y i s q u e r y i n g t h e l a s t 1 0 0 e n t r i e s o f t h e s y s t e m e v e n t l o g . & n b s p ; O p e n u p t h e g e n e r a t e d R S S f i l e i n y o u r f a v o r i t e R S S r e a d e r a n d s e e h o w i t l o o k s . < B R > < B R > - - < B R > K e i t h < B R > < B R > < F O N T f a c e = C o u r i e r > F i l e : E v e n t L o g R s s . p s 1 < B R > $ e v e n t s = g e t - e v e n t l o g S y s t e m - n e w e s t 1 0 0 | s o r t T i m e G e n e r a t e d - d e s c < B R > $ r s s F i l e n a m e = ' c : \ i n e t p u b \ w w w r o o t \ e v e n t l o g . r s s ' < B R > < B R > $ r s s C o n t e n t = @ " < B R > & l t ; r s s v e r s i o n = " 2 . 0 " & g t ; < B R > & n b s p ; & n b s p ; & n b s p ; & l t ; c h a n n e l & g t ; < B R > & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & l t ; t i t l e & g t ; S y s t e m E v e n t L o g f o r $ ( [ E n v i r o n m e n t ] : : M a c h i n e N a m e ) & l t ; / t i t l e & g t ; < B R > & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & l t ; l i n k & g t ; h t t p : / / $ ( [ s y s t e m . N e t . D n s ] : : G e t H o s t B y N a m e ( ' l o c a l h o s t ' ) ) / $ r s s F i l e n a m e & l t ; / l i n k & g t ; < B R > " @ < B R > < B R > < B R > f o r e a c h ( $ i t e m i n $ e v e n t s ) { < B R > & n b s p ; & n b s p ; & n b s p ; $ r s s C o n t e n t + = @ " < B R > & n b s p ; & n b s p ; & n b s p ; < B R > & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & l t ; i t e m & g t ; < B R > & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & l t ; t i t l e & g t ; $ ( $ i t e m . I n d e x ) - $ ( $ i t e m . E n t r y T y p e ) - $ ( $ i t e m . S o u r c e ) - $ ( $ i t e m . E v e n t I D ) & l t ; / t i t l e & g t ; < B R > & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & l t ; p u b D a t e & g t ; $ ( $ i t e m . T i m e G e n e r a t e d . T o S t r i n g ( ' R ' ) ) & l t ; / p u b D a t e & g t ; < B R > & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & l t ; d e s c r i p t i o n & g t ; $ ( [ S y s t e m . W e b . H t t p U t i l i t y ] : : H t m l E n c o d e ( $ i t e m . M e s s a g e ) ) & l t ; / d e s c r i p t i o n & g t ; < B R > & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & l t ; / i t e m & g t ; < B R > " @ & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; & n b s p ; < B R > } < B R > < B R > $ r s s C o n t e n t + = @ " < B R > & n b s p ; & n b s p ; & n b s p ; & l t ; / c h a n n e l & g t ; < B R > & l t ; / r s s & g t ; < B R > " @ < B R > < B R > $ r s s C o n t e n t & g t ; $ r s s F i l e n a m e < / F O N T > < / B O D Y > < / H T M L >

Keith Hill [MVP]

unread,
Aug 22, 2007, 9:47:58 PM8/22/07
to
You might also want to filter the entries for just errors and warnngs:
 
$events = get-eventlog System -newest 100 | ?{$_ -match 'error|warn'} | sort TimeGenerated -desc
 
--
Keith
"Mark Wilson" <ma...@markwilson.co.uk> wrote in message news:1187826121.6...@r23g2000prd.googlegroups.com...
Try this - note it only is querying the last 100 entries of the system event log.  Open up the generated RSS file in your favorite RSS reader and see how it looks.

--
Keith

File: EventLogRss.ps1
$events = get-eventlog System -newest 100 | sort TimeGenerated -desc
$rssFilename = 'c:\inetpub\wwwroot\eventlog.rss'

$rssContent = @"
<rss version="2.0">
    <channel>
        <title>System Event Log for $([Environment]::MachineName)</title>
        <link>http://$([system.Net.Dns]::GetHostByName('localhost'))/$rssFilename</link>
"@


foreach ($item in $events) {
    $rssContent += @"
   
        <item>
            <title>$($item.Index) - $($item.EntryType) - $($item.Source) - $($item.EventID)</title>
            <pubDate>$($item.TimeGenerated.ToString('R'))</pubDate>
            <description>$([System.Web.HttpUtility]::HtmlEncode($item.Message))</description>
        </item>
"@       
}

$rssContent += @"
    </channel>
</rss>
"@

$rssContent > $rssFilename

Marco Shaw

unread,
Aug 23, 2007, 7:33:22 AM8/23/07
to

Windows Server 2008 has a feature like this, but that likely doesn't
help you today...

Marco

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com

Hal Rottenberg

unread,
Aug 23, 2007, 8:50:30 AM8/23/07
to
On Aug 22, 7:42 pm, Mark Wilson <ma...@markwilson.co.uk> wrote:
> This sounds fine, except that the XML produced by export-clixml is not
> RSS. Does anyone know how I can convert it (or can anyone offer any
> advice?).

This RSS / ATOM library might come in handy if someone were to want to
create some more flexible scripts or cmdlets: http://www.codeplex.com/FeedDotNet


Marco Shaw

unread,
Aug 23, 2007, 8:59:00 AM8/23/07
to

I was sure I saw mention of a RSS class being added in .NET 3.5, but I
have it installed, and cannot locate it.

You might also like www.rssbus.com, but if you're looking for remote
connectivity, I think they expect to charge for that.

Their desktop/local version is free.

Keith Hill [MVP]

unread,
Aug 23, 2007, 11:27:48 AM8/23/07
to
"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:#loKhVY5...@TK2MSFTNGP03.phx.gbl...

> Mark Wilson wrote:
>> I'm just learning PowerShell but one of the examples I saw today
>> involved reading an event log and filtering the results. It struck me
>> that if I could then export this as RSS (using export-clixml) then I
>> could have administrators subscribe to a feed which published
>> important events.
>>
>> This sounds fine, except that the XML produced by export-clixml is not
>> RSS. Does anyone know how I can convert it (or can anyone offer any
>> advice?).
>>
>> TIA, Mark
>>
>
> I was sure I saw mention of a RSS class being added in .NET 3.5, but I
> have it installed, and cannot locate it.

There is a Rss20FeedFormatter class as well as an Atom10FeedFormatter class
in the System.ServiceModel.Syndication namespace. Cool.

--
Keith

Marco Shaw

unread,
Aug 23, 2007, 3:01:14 PM8/23/07
to

> There is a Rss20FeedFormatter class as well as an Atom10FeedFormatter
> class in the System.ServiceModel.Syndication namespace. Cool.

"Syndication" is the key word I was missing/forgetting.

Thanks Keith.

Lance

unread,
Aug 24, 2007, 12:41:20 PM8/24/07
to
On Aug 23, 7:59 am, Marco Shaw <marco.shaw@_NO_SPAM_gmail.com> wrote:
> Mark Wilson wrote:
> > I'm just learning PowerShell but one of the examples I saw today
> > involved reading an event log and filtering the results. It struck me
> > that if I could then export this as RSS (using export-clixml) then I
> > could have administrators subscribe to a feed which published
> > important events.
>
> > This sounds fine, except that the XML produced by export-clixml is not
> > RSS. Does anyone know how I can convert it (or can anyone offer any
> > advice?).
>
> > TIA, Mark
>
> I was sure I saw mention of a RSS class being added in .NET 3.5, but I
> have it installed, and cannot locate it.
>
> You might also likewww.rssbus.com, but if you're looking for remote

> connectivity, I think they expect to charge for that.
>
> Their desktop/local version is free.
>

More info on the RSSBus solution, if you install RSSBus on the machine
next to Powershell, you can convert any powershell command output into
an RSS feed (or atom, json, etc). It comes with a demo feed that is
generated by get-process.

Lance
http://geekswithblogs.net/Lance

0 new messages