Twitter PowerPack for PowerGUI

Having had some fun previously putting together some PowerPacks for PowerGUI, I had an idea that it would be quite a good tool to use with Twitter. One thing I found annoying with the web interface for Twitter was that it was difficult to see a full list for who you were following and who was following you - you could only see 20 people per page. After Steve Murawski put together his list of Powershell Twitterers at the Mind of Root website I started playing around with some of the ways you could use Powershell to access Twitter data.

Not long afterwards James O’Neill published some PowerShell Twitter functions on his blog which pretty much covered everthing I was looking to cover. If you are a Twitter and PowerShell user I seriously urge you to check these out because they are a really cool way to mess around with some of the data you can get from Twitter. The data is available in XML format, which with PowerShell is very straightforward to handle. The below example shows the Get-TwitterFriend function (I have tweaked James’ code slightly so that it returns all the people you follow, not just the first page of 100) . Essentially you supply some credentials, go get the XML page from the Twitter website, convert it into an XML object and access elements of the XML document since we can get to properties of the XML object.

Function Get-TwitterFriend { param ($username, $password, $ID) if ($WebClient -eq $null) {$Global:WebClient=new-object System.Net.WebClient } $WebClient.Credentials = (New-Object System.Net.NetworkCredential -argumentList $username, $password) $nbrofpeople = 0 $Friends = @() if ($ID) {$URL=“$ID.xml?page="} else {$URL=“"} do { $Friends += (([xml]($WebClient.DownloadString($url+($nbrofpeople/100 +1)))).users.user ) # Returns the user’s friends, with current status inline, in the order they were added as friends. # If ID is specified, returns another user’s friends #id:  Optional.  The ID or screen name of the user for whom to request a list of friends. $nbrofpeople += 100 } while ($Friends.count -eq $nbrofpeople) $Friends }

The XML from Twitter for a user looks like this.

14691415 ebgreen <screen_name>ebgreen</screen_name> St. Louis − IT Swiss army knife. Lots of powershell right now and VBScript always. − <profile_image_url> </profile_image_url> false <followers_count>111</followers_count> <profile_background_color>1A1B1F</profile_background_color> <profile_text_color>666666</profile_text_color> <profile_link_color>2FC2EF</profile_link_color> <profile_sidebar_fill_color>252429</profile_sidebar_fill_color> <profile_sidebar_border_color>181A1E</profile_sidebar_border_color> <friends_count>164</friends_count> <created_at>Wed May 07 20:31:13 +0000 2008</created_at> <favourites_count>6</favourites_count> <utc_offset>-21600</utc_offset> <time_zone>Central Time (US & Canada)</time_zone> − <profile_background_image_url> </profile_background_image_url> <profile_background_tile>true</profile_background_tile> <statuses_count>474</statuses_count> false 0 − <created_at>Mon Apr 27 20:47:23 +0000 2009</created_at> 1632413267 − You did sort of ask for it. RT @cshanklin: I desperately need a retweet filter. Twitterfall false <in_reply_to_status_id/> <in_reply_to_user_id/> false <in_reply_to_screen_name/>

So to access some of these properties we could do something like this:

Get-TwitterFriend $userName $password | Select-Object name,screen_Name,url,id

Rather than try re-inventing the wheel and consequently saving myself a bunch of time for the PowerPack, I took these pre-made functions and plugged them into PowerGUI. The results for the initial release are the below:

So if you run the above Get-TwitterFriend function in the PowerPack you get a nice grid view of the people you follow and can easily sort them into alphabetical order by clicking on the Name column.

One of my favourite things is the ability to search Twitter for a particular subject and return the Top 20 people who have posted about that subject recently - this is great if you are looking to check out a particular community to find who might be good people to follow. For instance if you wanted to check out who’s talking about PowerShell on Twitter you would get some results like the below:

Another thing you may find useful in the pack is to check out some of the lists of people published on websites who are known to talk about topics on Twitter, so far I have included the list of PowerShell Twitterers over at the Mind of Root website and Alan Renouf’s list of people who talk about VMWare. I’ve included an action in the PowerPack which once you have pulled down the link and either selected some or all of the people from the list allows you to add them to the list of people you follow on Twitter.

There’s other stuff in the PowerPack, I encourage you to go check it out; give me any feedback, particularly stuff you might like to see added and also check out James’ PowerShell Twitter functions on their own.

Hope you find it useful.