Using Twitter and PowerShell to Find Technical Information and Join a Community

Using PowerShell and a little bit of .NET Framework and XML knowledge, it is possible to delve a little deeper into the information which is potentially available to you from Twitter. Jonathan explains about Twitter and shows how to use Powershell to access twitter automatically.

For somebody so interested in new technology, particularly within the Enterprise workplace, I remain healthily sceptical of the latest new fads and how useful they might actually be. A colleague of mine had for some time been pestering me to use social networking sites saying I was missing out on some great tools for information gathering and also being part of various online communities. As far as my initial look took me I couldn’t really see much benefit past a bit of fun time wasting at idle parts of the day and potentially having to deal with some privacy issues.

After a while though, seeing how enthused about it he was and how much he seemed to be getting out of it I gave in and signed up. There are plenty of social networking sites out there these days, each of which has their possible different uses in different situations – in this article I’m going to look at the micro-blogging service Twitter and how you can use it to get technical information online and also participate in a community.

As with many ideas the best ones can typically be the simplest ones. Using messages of up to 140 characters, tweets, can be published to your Twitter page and consequently anybody can be subscribed to your updates with a variety of different applications. Based on SMS messaging technology they typically describe what you are doing right at that moment in time, but instead of being read by just one person you have sent a text to, anybody following you on Twitter is able to read them. These can range from the informative “I just fixed this technical problem by doing x…..” to the banal “Just missed the bus, I’m going to be late for work”. It’s these trite comments which are often highlighted as Twitter being a great time waste, but if you ignore these there is some great technical content just waiting for you to grab hold of it.

Getting Started

First of all you will need to sign up for an account at Twitter. Once complete you can use the web interface as a basic starting point.

765-Twitter1.jpg

This is a typical view of a Twitter home page. From here you can post updates, add Twitter users you wish to follow, see recent updates from those you are following, view a list of those following you, carry out some basic searching and view trending topics (some of the current most popular words being talked about on Twitter, which usually gives a good barometer for some of the most commonly talked about news stories of that point in time).

Tips for getting started

  • Twitter is not very useful if you are not following anybody! Use the search bar above or http://search.twitter.com/ to perform a search of Twitter on a topic. You will see a list of updates including the topic; anything that looks interesting simply start following the person who published the tweet.
  • Be careful though, don’t follow too many people all at once initially otherwise you’ll be subjected to a tidal wave of tweets which you can’t keep up with and you’ll be wondering why you started using Twitter.
  • You don’t have to follow everybody who follows you. Although it may seem the correct etiquette to do so, again you may end up with updates you are not really interested in – check out the person’s recent updates first to see if they appeal to you.
  • Don’t worry if you don’t look at Twitter for a few hours or even days – it’s not like email where you need to go back and catch up, rather something you can dip in and out of as and when you have the time or inclination.
  • Be careful what you post. Once it’s there, although you can delete it, it doesn’t take long for a message written in haste to be sent round the globe can cached on a server somewhere.
  • Also it’s probably not a good idea to tell the world that you are going on holiday and leaving an empty house for two weeks. (See:Note to Self: Don’t Tweet Vacation Plans If you want to be extra cautious you can approve each person who wishes to follow your Twitter updates before you let them see the updates.

If you are somebody who already likes to engage with a technical community and share content you can use Twitter to help promote a new post on your blog, a new episode of a podcast or an update for an open-source project you work on.

For instance as well as manually posting a link to a new blog post you have just written, why not use a service like http://twitterfeed.com to automatically publish a tweet for the new post. Or over at the Get-Scripting Podcast we have created a Twitter account for the podcast and use it to keep listeners up-to-date with show releases and what’s coming up on future shows.

It never ceases to amaze me of new uses for Twitter that people find. At a technical event I attended recently the presenter encouraged those in the audience to send him questions via Twitter during his presentation. I have also attended another event in the past which was a Q&A session; during the session I put out a tweet saying where I was and ended up asking questions for people elsewhere sending me them via Twitter. Another example comes from a situation where I had made a forum post which had gone unanswered for a few days; I was particularly keen to get an answer so I tweeted about it and within a couple of hours I had some answers which had previously started to look like they were not going to appear.

A number of corporate and marketing types have begun to cotton on to this real-time and potential personal interaction with customers and will provide Twitter feeds about their products and company. Whilst IT pros may not always be particularly interested in marketing spiel it can be useful to say find out when new updates for a product are released or maybe follow the product manager who may ask what kind of features / updates people would like to see in a product. It’s great that these opportunities now exist in these more open times and even massive companies like Microsoft who may in the past have hidden away the technical people behind the marketeers are now much more open and easier to interact with.

Twitter Clients

Fairly soon you will find that the basic web page for Twitter doesn’t have enough features for your now hopefully growing Twitter use. Since Twitter publishes an (API) for accessing their service there are a plethora of clients out there you can use instead. A couple of the most commonly used clients on desktop and laptop machines are (Thwirl) and TweetDeck, both of which are free to use. Using a client gives you a feature rich experience for using Twitter.

Twhirl

Twhirl gives you features like notifications for new messages, spell checking, coloured replies (green) and direct messages (yellow), posting images to twitpic and automatically finding tweets mentioning your username – in the web client you won’t see replies from people unless you are following them.

765-Twitter2.jpg

TweetDeck

TweetDeck offers fairly similar features to Twhirl, with one particularly great extra feature – the ability to maintain extra columns based on searches. So say for instance you are interested in what people are talking about Exchange 2010, you can create a search based on the phrase ‘Exchange 2010’ and view the results in a column next to your main Twitter feed. The difference being that the results are dynamic, so the client will poll for new results allowing you to keep track of conversations.

765-Twitter3.jpg

Once you start to see information coming in like this, not only will you be really up-to-date with all the latest news of the topics you are interested in, you’ll find yourself wanting to engage with these communities, join in by posting your own information and starting conversations with people with similar interests.

Mobile devices

Most IT people these days will likely be carrying around some kind of Internet connected mobile device for everything from keeping up with emails to remote administration, naturally there are Twitter clients for these devices too. I won’t cover too much on these since you are far more likely to use Twitter on a mobile device for things like up-to-date travel information, but you may wish to view some topics whilst out and about.

Windows Mobile

Twikini seems to be one of the most recommended clients for Windows Mobile based devices. It has most of the features you would expect from a Twitter client.

iPhone

TwitterFon gets a lot of good reviews and appears generally popular.

As with most of these kinds of things it’s probably a decision for personal preference and worth trying out a few options to see what works best for you.

PowerShell and Twitter

Since the Twitter API enables you to access their offerings via a web service if you had the inclination you could of course write your own client. However, if you don’t want to go quite that far you can use PowerShell and some very straightforward .NET code to get some very interesting information out of Twitter. James O’Neill has published on his blog a set of PowerShell functions which he has put together so that you can interact with Twitter direct from the command line.

Tip: The downloadable functions are stored in a .ps1 file, i.e. a PowerShell script file. To make them accessible in PowerShell you can either include them in your profile so they are available every time you run PowerShell, or for one off use add them to your current session like so:

(Note the dot, then a space, then a second dot)

Most of the information you wish to get from Twitter is available via an XML file; PowerShell supports manipulating XML files really well and is particularly straightforward for a beginner. The code is stored in the Function Get-TwitterSearch for ease of use to run the searches.

(Note: The below code is slightly amended from James’ original function since at the time of writing Twitter appear to be making their search available via Atom rather than RSS;the RSS search gives intermittent errors)

At that point we could stop the search there, but that would only have given us 100 results. It may well be better to get more information, in which case the search function has a ‘deep’ switch which essentially runs the search another 15 times further back each time in the Twitter timeline. A good example for why you might wish to do this is searching for people who Twitter about topics you are interested in and might be interesting to follow.

If we carry out a ‘deep’ search and store the results into a variable we can then use standard PowerShell techniques to manipulate the data into something potentially interesting. For instance earlier we used TweetDeck to search on ‘Exchange 2010’ and it would show recent and new posts about that topic. Let’s run the same search using the Get-Twitter search function.

Now let’s group the results by the author of the tweets, sort them by the authors with the most tweets, pick out the top 20 and display them in a table with their count and the author’s name.

765-Twitter4.jpg

You can then checkout the authors in question by looking at http://twitter.com/authorname for their recent updates and see if they might be interesting to follow. Exchange 2010 is still a relatively new topic so the numbers above aren’t massive. The below screen shows a search on PowerShell and gives a pretty good indication of the people who Twitter about it a lot.

765-Twitter5.jpg

You can obviously now run these searches based on the topics of your choice and find people worth following.

(Note: Beware you may get HTTP errors like ‘502 Bad Gateway’ or ‘503 Service Unavailable’ when searching, particularly if you run multiple ‘deep’ searches or are using it at peak Twitter usage times. This is because the Twitter service uses rate limits to throttle back accounts running too many searches; they also currently sometimes have capacity issues at peak times which can mean running these kinds of processes are not quite as reliable as you would hope.)

Something else you can check out is your list of Twitter friends. On the webpage it’s quite difficult to see a complete list of people you are following; below James has put the ability to pull this data down into a PowerShell function. (Note I have amended the function slightly from the original so that if you are following more than 100 Twitter users you will see them all; the original function only pulled down the first page of 100)

Essentially we again create a new WebClient object, give it the credentials to use for Twitter, pull down the data in XML format and return the data about the users.

So to run the function and see your friends listed in alphabetical order with the Name, Location and Description properties, you would type:

which would give you results like the below

765-Twitter6.jpg

There are nine other functions in James’ Twitter function library for you to play with including things like Get-TwitterReply to see replies you have sent, Publish-Tweet to send a message to Twitter or Add-TwitterFriend to add people to your friends list. For instance say you have run one of the previously mentioned searches and found the top 20 people talking about the topic you are interested in; you could then pipe the results onwards and using the Add-TwitterFriend function add all of them to your friends list in one easy go.

Twitter PowerPack for PowerGUI

If you’re not 100% comfortable with working totally from the shell yet, but are interested in some of the functionality that it can provide, then I have plugged James’ functions, plus some other extras, into a PowerPack for Quest Software’s free product PowerGUI. This provides a graphical front-end to PowerShell scripts and produces results into a grid format. Simply download the PowerGUI tool from the PowerGUI website and the Twitter PowerPack from the library and you will see the below choices.

765-Twitter7.jpg

First of all use the Credentials node to store your Twitter username and password into a global variable so that you don’t need to supply them each time you run one of the scripts. You can then run any of the script nodes and see the results in the grid pane. In the below example I’m using the Get-TwitterFollowers script to see the list of people who follow me and I’ve clicked on the name column to sort them alphabetically.

765-Twitter8.jpg

Another way to find people on Twitter to follow is to use one of the maintained lists of people who talk about particular subjects. A couple of these lists feature in the Twitter PowerPack, below is the VMWare list maintained over at the http://Virtu.al.net website.

Clicking the script node will produce a list of the VMWare Twitterers; you could select multiple or all people and then use the Add-TwitterFriendFromList action based on the previously mentioned Add-TwitterFriend function to add these all to your follow list in one go.

765-Twitter9.jpg

A potential drawback of these lists is that they are statically maintained. To use a more dynamic approach you could use a website like http://www.tweetertags.com where Twitter users tag themselves with subjects they are interested in and you can search these tags for people to follow.

Not surprisingly you can search these tags using PowerShell and I’ve included that in the Twitter PowerPack. For instance using the Get-TweeterTag node and searching for ‘Exchange’ tags on the website returns the following list of users; you could then use the Add-TweeterFriend action to add a multiple selection of people to your follow list.

765-Twitter10.jpg

Conclusion

Twitter is one of those things where you can get as much out of it as you want to; it can be anything from a fun time-wasting tool to something really useful to find information and people around the globe with similar interests to yourself. The various Twitter clients for differing devices can help you keep in touch with these communities wherever you are.

Using PowerShell and a little bit of .NET Framework and XML knowledge you can delve a little deeper into the information which is potentially available to you from this social network.