INTRODUCTION (WordPress to Twitter)  

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 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 –

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

MAKING IT WORK

  1. Get Random PowerShell Articles from WordPress
    • 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.
    • 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 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.2
    • Once I get all articles I’ve to use Get-Random cmdlet to select some random articles.
  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
    • 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.
    • Using the above function you’ll get a short URL something like this1
  3. Hashtag important keywords in your TweetHashtag 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.
  4. Tweet the content
  • Combine the Article topic and the shortened URL in one string to prep the tweet content
  • To publish the tweet, you can install PoshTwit module from Powershell gallery using below cmdletwordpress to twitter
  • 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 themwordpress to twitter
  • Once you are all set, use the Publish-Tweet cmdlet, which will automatically tweet content to your twitter profile2

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.

2

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 and depend upon what someone has already created, 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!


My new book :  PowerShell Scripting Guide to Python

This PowerShell Scripting guide to Python is designed to make readers familiar with syntax, semantics and core concepts of Python language, in an approach that readers can totally relate with the concepts of PowerShell already in their arsenal, to learn Python fast and effectively, such that it sticks with readers for longer time.

“Use what you know to learn what you don’t. ” also known as Associative learning.

Book follows a comparative method to jump start readers journey in Python, but who is the target audience? and who should read this book –

  • Any System Administrator who want to step into Development or Programming roles, and even if you don’t want to be a developer, knowledge of another scripting language will make your skill set more robust.
  • Python Developers who want to learn PowerShell scripting and understand its ease of user and importance to manage any platform.

Python is one of the top programming languages and in fast changing IT scenarios to DevOps and Cloudto the future – Data ScienceArtificial Intelligence (AI) and Machine Learning Python is a must know.

But this PowerShell Scripting guide to Python would be very helpful for you if you already have some knowledge of PowerShell

NOTE! This is a Leanpub “Agile-published” book. That means the book is currently unfinished and in-progress. As I continue to complete the chapters, we will re-publish the book with the new and updated content. Readers will receive an email once a new version is published!

While the book is in progress, please review it and send any feedback or error corrections at [email protected]

Optical Character Recognition

Subscribe to our mailing list

* indicates required