



| When I don’t have any real projects to work on I make up stupid tasks to build to keep me occupied. Here is an other one |
|
<Types> |
So after a period of trail and error I made this line:
| $rss = [xml](new-object System.Net.WebClient).DownloadString($Url) |
And of course ones I found the solution I got the same line from my friend “Google” ..snif….snif.. I also added some forms to make it look good. There were two things I couldn’t figure out.
These questions bug me so if any of you know the answer to the problems above don’t hesitate to comment to this post.
| First the script reeds the feed from the URL with the XML file and then reeds the feeds from the channel in the VAR $feeds . |
Then the form is build with all it’s objects like $listbox, $textbox. Also a handler is added to the form. It detects when Return is pressed and when so the form shows de body of the selected post title.
When I was half way building this script I thought what if I use this feed reader on my servers to read an internal blog. Than I could give my servers commands to execute trough a blog…. Ok it is far fetched but I think it can work and that’s my point, Powershell has some boundaries but most of them are in your head I think.
# Select a post title and press return to get the # post body text. $Url = "http://blogs.msdn.com/powershell/rss.xml" $rss = [xml](new-object System.Net.WebClient).DownloadString($Url) $feeds = $rss.rss.channel.item [reflection.assembly]::LoadWithPartialName("System.Windows.Forms") $form = new-object windows.forms.form $form.Text = "RSS titles" $form.StartPosition = "CenterScreen" $form.Size = New-Object System.Drawing.Size(600,400) $form.KeyPreview = $true # initialize listbox $listbox = new-object windows.forms.listbox $listbox.Width = 500 $listbox.Location = New-Object System.Drawing.Size(10,10) # initialize textbox $textbox = new-object system.windows.forms.textbox $textbox.Location = New-Object System.Drawing.Size(10,120) $textbox.Multiline = $true $textbox.Width = 500 $textbox.Height = 200 $textbox.ScrollBars = "Vertical" $textbox.Visible = $false $index = -1 $form.add_keydown({if ($_.KeyCode -eq "Return") { $index = $listbox.selectedindex if ($index -gt -1) { #--------------start one line------------# $textbox.text = $feeds[$index] | Select-Object Description | ConvertTo-Html #--------------end one line--------------# $textbox.Visible = $true } } }) # Fill teh listbox with the RSS titles foreach ($feed in $feeds) { $listbox.items.add($feed.title) } # Add alle objects to the form $form.controls.Add($listbox) $form.Controls.Add($textbox) $form.ShowDialog() |


More Options ...
Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 