Lendo RSS do Virtual PASS BR Usando Powershell


Então pessoal, após um longo tempo sem blogar estou de volta.

Vamos ver bastante Powershell com SQL Server.

A dica de hoje é como ler o RSS do Virtual PASS BR usando Powershell. Veremos o quanto é simples :

  • Vamos criar um função chamada Search-RssVirtualPassBr :
   1: function Search-RssVirtualPassBr {

   2: }

   1: $rssFeed = [xml](New-Object System.Net.WebClient).DownloadString('http://feeds.feedburner.com/SqlVirtualPassBrasil/')

  • Depois puxamos a propriedade item e pipe pro select-object. Se quisermos ver todas as informações colocamos Select *, mas neste caso so me interessa o Creator, Title e Link
   1: $rssFeed.rss.channel.item |    Select-Object Creator,Title,Link

  • O Script final fica
   1: function Search-RssVirtualPassBr {

   2:     $rssFeed = [xml](New-Object System.Net.WebClient).DownloadString('http://feeds.feedburner.com/SqlVirtualPassBrasil/')

   3:     $rssFeed.rss.channel.item |    Select-Object Creator,Title,Link

   4: }

:

e o rsultado final é :

image

Podemos agora jogar pra um txt, com pipe pro cmdlet Out-File

   1: Search-RssVirtualPassBr | Out-File c:\temp\teste.txt

Ou até mandar pra uma grid :

   1: Search-RssVirtualPassBr | Out-GridView

image

 

Agora, se você realmente quer ver uma coisa bem legal, sugiro baixar a ShowUI do codeplex. É um projeto que está mudando a cara do Powershell.Com ela você cria interfaces WPF usando scripts.

Muito Obrigado ao PowerShell MVP Douglas Finke (twitter|blog) , que faz parte do time de criação do projeto, por me ajudar a montar esse script final

   1: function Search-RssVirtualPassBr {

   2:     $rssFeed = [xml](New-Object System.Net.WebClient).DownloadString('http://feeds.feedburner.com/SqlVirtualPassBrasil/')

   3:     $rssFeed.rss.channel.item |    Select-Object Creator,Title,Link

   4: }

   5:  

   6:  

   7: $ws = @{

   8:     WindowStartupLocation = "CenterScreen"

   9:     SizeToContent = "WidthAndHeight"

  10:     Title = "Rss Feed - Virtual Pass BR"

  11: }            

  12:  

  13: $titleStyle = @{

  14:     Margin = 5 

  15:     TextWrapping = "Wrap"

  16:     Foreground = "White"

  17:     FontSize = 15

  18: }

  19:  

  20: $textBlockStyle = @{

  21:     Margin = 5 

  22:     TextWrapping = "Wrap"

  23:     Foreground = "AntiqueWhite"

  24:     FontSize = 11

  25: }

  26:  

  27: New-Window @ws -Show {

  28:     ListBox -Background Blue -ItemTemplate {

  29:         Grid -Columns Auto, 300, 300 -Rows 2 {

  30:             TextBlock -Name Title   -Column 0 -ColumnSpan 2 -Row 0 @titleStyle 

  31:             TextBlock -Name Creator -Column 0 -Row 1 @textBlockStyle 

  32:             TextBlock -Name Link    -Column 1 -ColumnSpan 2 -Row 1 @textBlockStyle 

  33:         } | ConvertTo-DataTemplate -binding @{

  34:                 "Title.Text" = "title"

  35:                 "Creator.Text" = "creator"

  36:                 "Link.Text" = "link"

  37:             }

  38:  

  39:     } -DataContext {Search-RssVirtualPassBr} -DataBinding @{ItemsSource="."} 

  40:      

  41: }

e o resultado é :

image

Can you see this ? Can you feel this ? Can you feel the Power ?

POWERSHELL ROCKS !!!

If I had to
I would put myself right beside you
So let me ask
Would you like that?
Would you like that?

And I don’t mind
If you say this love is the last time
So now I’ll ask
Do you like that?
Do you like that?

Something’s getting in the way
Something’s just about to break
I will try to find my place in the diary of Jane
So tell me how it should be

The Diary of Jane

Breaking Benjamin

About Laerte Junior

Laerte Junior Laerte Junior is a SQL Server specialist and an active member of WW SQL Server and the Windows PowerShell community. He also is a huge Star Wars fan (yes, he has the Darth Vader´s Helmet with the voice changer). He has a passion for DC comics and living the simple life. "May The Force be with all of us"
This entry was posted in Powershell, Virtual Pass BR. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s