Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2010-10-03
To check a twitter feed using PowerShell, you must have an URL to an XML feed (probably RSS). Open the web site of the account you’re interested in (http://www.twitter.com/username/) and find the RSS link. Mine is http://twitter.com/statuses/user_timeline/33177615.rss.
You can load the URL into a variable like so:
$url="http://twitter.com/statuses/user_timeline/33177615.rss"
Then, the Net assembly must be loaded. Use the Load function of the System.Reflection.Assembly class (without inserting any Enter strokes).
[System.Reflection.Assembly]::Load("System.Net, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
If you’re not sure about public key token or version, check you assembly folder in your Windows installation folder. Next, you create a web client from the assembly that you just loaded.
$wcli=New-Object System.Net.WebClient
Use the OpenRead function of the web client to acquire a web stream.
$s=$wcli.OpenRead($url)
Use the stream object to create a stream reader.
$r=New-Object System.IO.StreamReader($s)
To save the result stream data in a variable, call the ReadToEnd function of the reader. You then have to close the reader and destroy the web client.
$response=$r.ReadToEnd() $r.Close() $wcli.Dispose()
You can just type the name of the variable to see its content.
$response
You should now see my twitter feed!
Categories: PowerShell
Tags: PowerShell
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
[…] This post was mentioned on Twitter by Anders Hesselbom, Sean Kearney. Sean Kearney said: RT @ahesselbom: New blog post: Checking a twitter feed using PowerShell http://bit.ly/anWdF0 […]