INTRODUCTION :

I’m always short of time and abundant of work since I make PowerShell scripts and write articles about them I’ve to also spend about an hour a day on social media sharing my content/blog posts and engaging in PowerShell communities. But the problem with social media is – Either you are Jeffery Snover himself 🙂 or most of the times nobody cares about your content and the Facts says: your post on Twitter or Facebook feed have an average lifetime 10-15 mins for a set of eyes to catch it or it will disappear in the abundance of noise out there.

So! *Takes a deep breath* You’ve to share the content you are creating multiple times on Twitter to reach out to more and more people = MORE TIME, otherwise, it doesn’t make much sense putting efforts writing those blog posts and creating those scripts if nobody is reading them.

THE IDEA:

How about if I can automate sharing Mulitple Random blog posts to twitter, few times a day, without even investing the time I would’ve actually spent doing that manually. Sounds great, right? ( Well, to me 🙂 )

Okay, Enough of talking, let’s begin working. So for better understanding let me break down what we want to achieve in some steps –

Figure out a way get a random Powershell article [Topic and URL] from my blog [http://Geekeefy.wordpress.com] Shorten the URL because a Tweet has a character limit of 140 words And yeah! We’ve to #HashTag some keywords Like #PowerShell in our tweet Then just Tweet the Topic, Shortened URL, and hashtags.

MAKING IT WORK:

Step 1 [Get some random Powershell article]

In order to get few random articles from my blog, a simple Invoke-WebRequest on my blog URL would work like a charm, and get me the parsed HTML content of the homepage.

NOTE: You’ve to customize the script to handle your blog because you’ve to filter out exact HTML tags to get the data residing within them , which would be different for every website.

on my blog URL would work like a charm, and You’ve to because , which would You can use static data instead where in you put all Article topics and URLs and utilize it in publishing tweets , but that is not our case because we’ve to regularly update this static data whenever I write a new article.

, but that is not our case because we’ve to regularly update this static data whenever I write a new article. But wait on the homepage on my blog not all links populate at once until you scroll down, so I’m gonna iterate all pages and get the links to the articles I’ve written.

Once I get all articles I’ve to use Get-Random cmdlet to select some random articles

Step 2 [Shorten the URL of the article]

You can use many Web REST API’s to get a short URL for a long URL because Tweet has a word limit of 140 characters

for a long URL I used Google API’s for this following is the function, but first, you’ve to subscribe the API here and get an API key to make it work.

for this following is the function, but first, you’ve to subscribe the API here and Using the above function you’ll get a short URL something like this

Step 3 [#Hashtag important keywords in your Tweet]

Hashtag your topics so that if people search using a particular Hashtags they get reach your tweet easily, also it’s easier for you to track them.

Step 4 [Tweet the content]

Combine the Article topic and the shortened URL in one string to prep the tweet content

in one string to prep the tweet content To publish the tweet, you can install PoshTwit module from Powershell gallery using below cmdlet

using below cmdlet Once you have the module on your local machine and you can feed in your Tweet content with secret tokens and keys you get from your twitter account , follow this link to get the exact steps to obtain them

, follow this link to get the exact steps to obtain them Once you are all set, use the Publish-Tweet cmdlet, which will automatically tweet content to your twitter profile

SCRIPT :

Wrapping up all the steps in the script looks something like this

HOW TO RUN :

Run the script with parameters like in the below animation

and you’ll see random blog posts from your archives getting tweeted in the defined interval on you Twitter Profile. If you want you can also Prefix something like “From the Blog Archives: Topic” for your twitter followers.

NOTE :

There are plenty of tools Like IFTTT already on the internet, that may provide you recipes to achieve this, but again it’s something you can’t customize per your needs, moreover creating your own thing is far more fun and satisfying 🙂

POSSIBILITIES :

What if we can schedule one such script on a physical machine that is running 24X7 or a cloud instance which is always up?

It would definitely increase social media interactions and visibility to the work you are producing! Your content would be shared on social media even when you are sleeping and working on other things and for sure it will save you some time 🙂 which is scarce.

Hope you’ll find it useful, give me a shout on twitter if you like the content I share. Thank you very much for reading!

Follow @SinghPrateik