{"id":46,"date":"2019-07-29T17:10:17","date_gmt":"2019-07-29T17:10:17","guid":{"rendered":"https:\/\/www.practicalpowershell.com\/post\/tweeting-with-powershell"},"modified":"2020-03-08T06:29:07","modified_gmt":"2020-03-08T06:29:07","slug":"tweeting-with-powershell","status":"publish","type":"post","link":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/","title":{"rendered":"Tweeting with PowerShell"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg?resize=250%2C197&#038;ssl=1\" alt=\"\" width=\"250\" height=\"197\" class=\"alignleft size-full wp-image-292\" \/><\/a>PowerShell and Twitter.  Would seem like an odd pair.  However, you might find that there are some practical uses to the combination of these two tools.  Some may use it for scheduled social media events, or just general announcements.  It could be used as a marketing device to help broadcast information about a product as well.  Twitter and PowerShell combined provides a useful tool. <\/p>\n<p><strong>Twitter API&#8217;s <\/strong><\/p>\n<p>In order to make the connection to Twitter from PowerShell successful, you will need a PowerShell module to connect to Twitter&#8217;s API&#8217;s.  These modules will help send the correct token information in order to authenticate with Twitter and enable a connection.  Once the connection is established, these modules have various potential uses. <\/p>\n<p><em>Twitter API &#8211; Example 1 <\/em><\/p>\n<p>For this first example Twitter API, is one that was written some time ago by Trevor Sullivan who was a PowerShell MVP at one time and is now working with AWS.  His work can be found <a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/PowerShell-Twitter-Bot-9e9b8603\">HERE<\/a>. <\/p>\n<p><em>Twitter API &#8211; Example 2 <\/em><\/p>\n<p>This second example provides some slightly greater flexibility as well as the ability to preconfigure secrets and other items needed for API authentication with Twitter.  This one was written by Adam Bertram and it can be found <a href=\"https:\/\/adamtheautomator.com\/twitter-module-powershell\/\">HERE<\/a>.  He is also a Microsoft PowerShell MVP. <\/p>\n<p><strong>Where to schedule these to run? <\/strong><\/p>\n<p>Depending on your needs, availability and resources there are many places where to schedule your automatic tweeting.  Below are two examples of where we can set up PowerShell : <\/p>\n<p><em>OnPremises Server <\/em><\/p>\n<p>Using a server in your environment may be one of the easiest ways to automate your tweets.  See the code sample below for a working example of a PowerShell script used in automating tweets. Refer to this blog post for how to schedule your tweeting PowerShell script on a server &#8211; Schedule It! <\/p>\n<p><em>Azure Run Books <\/em><\/p>\n<p>Another possible place to run these is in an Azure RunBook.  There are some caveats.  It does take resources and thus it will cost something to run this in the service.  If you have an Azure account and have a way to pay for this, then setting up a run book in Azure is an option.   Make sure to read this article on how to set this up: <\/p>\n<p><em>Azure RunBook Setup <\/em><\/p>\n<p>The code sample at the bottom can also be used for an Azure RunBook as long as the API is loaded and the appropriate keys and are prepped. <\/p>\n<p><strong>Sample Code Automating Tweets <\/strong><\/p>\n<p>Now, depending on which API you are using you may need to do some extra work.  The code sample below use&#8217;s Adam&#8217;s Twitter<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\n# Store date for later<br \/>\n$Date = Get-Date -UFormat &quot;%m\/%d\/%Y&quot;<br \/>\n# Try to import the &#039;MyTwitter&#039; PowerShell Module we need to tweet with later<br \/>\nTry {<br \/>\n    Import-Module MyTwitter -ErrorAction STOP<br \/>\n} Catch {<br \/>\n    Exit<br \/>\n}<br \/>\n# Array of Tweets<br \/>\n$TweetList = @(<br \/>\n    &#039;This is a sample tweet &#8211; https:\/\/www.practicalpowershell.com&#039;<br \/>\n    &#039;Tweeting a message out &#8211;  https:\/\/www.PowerShellGeek.com&#039;<br \/>\n    &#039;All my tweets are here &#8211; https:\/\/www.twitter.com&#039;<br \/>\n)<br \/>\n# Send Dates for the next 2 months<br \/>\nIf ($Date -eq &quot;7\/29\/2019&quot;) {$TweetId = 0} # Week 1<br \/>\nIf ($Date -eq &quot;8\/7\/2019&quot;) {$TweetId = 1} # Week 2<br \/>\nIf ($Date -eq &quot;8\/14\/2019&quot;) {$TweetId = 2} # Week 3 <\/p>\n<p># Provision the tweet of the week<br \/>\n$Tweet = $TweetList[$TweetId] <\/p>\n<p># Publish the tweet<br \/>\nTry {<br \/>\n    Send-Tweet -Message  $Tweet -ErrorAction STOP<br \/>\n} Catch {<br \/>\n    Write-Verbose &#039;Failed to send tweet!&#039;<br \/>\n}<br \/>\n[\/sourcecode]<br \/>\nThere you have it.  A quick tip on how to use PowerShell to send out your tweets.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell and Twitter. Would seem like an odd pair. However, you might find that there are some practical uses to the combination of these two tools. Some may use it for scheduled social media events, or just general announcements. It could be used as a marketing device to help broadcast information about a product as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":[],"rop_publish_now_history":[],"rop_publish_now_status":"pending","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tweeting with PowerShell - Practical PowerShell<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tweeting with PowerShell - Practical PowerShell\" \/>\n<meta property=\"og:description\" content=\"PowerShell and Twitter. Would seem like an odd pair. However, you might find that there are some practical uses to the combination of these two tools. Some may use it for scheduled social media events, or just general announcements. It could be used as a marketing device to help broadcast information about a product as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical PowerShell\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-29T17:10:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-08T06:29:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg\" \/>\n<meta name=\"author\" content=\"damian\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"damian\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/\"},\"author\":{\"name\":\"damian\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"headline\":\"Tweeting with PowerShell\",\"datePublished\":\"2019-07-29T17:10:17+00:00\",\"dateModified\":\"2020-03-08T06:29:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/\"},\"wordCount\":571,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/PowerShellTweet.jpg\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/\",\"name\":\"Tweeting with PowerShell - Practical PowerShell\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/PowerShellTweet.jpg\",\"datePublished\":\"2019-07-29T17:10:17+00:00\",\"dateModified\":\"2020-03-08T06:29:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/PowerShellTweet.jpg?fit=250%2C197&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2019\\\/07\\\/PowerShellTweet.jpg?fit=250%2C197&ssl=1\",\"width\":250,\"height\":197},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/tweeting-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practicalpowershell.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tweeting with PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/\",\"name\":\"Practical PowerShell\",\"description\":\"PowerShell books written by experts\",\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/practicalpowershell.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\",\"name\":\"damian\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"caption\":\"damian\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tweeting with PowerShell - Practical PowerShell","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Tweeting with PowerShell - Practical PowerShell","og_description":"PowerShell and Twitter. Would seem like an odd pair. However, you might find that there are some practical uses to the combination of these two tools. Some may use it for scheduled social media events, or just general announcements. It could be used as a marketing device to help broadcast information about a product as [&hellip;]","og_url":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/","og_site_name":"Practical PowerShell","article_published_time":"2019-07-29T17:10:17+00:00","article_modified_time":"2020-03-08T06:29:07+00:00","og_image":[{"url":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg","type":"","width":"","height":""}],"author":"damian","twitter_card":"summary_large_image","twitter_misc":{"Written by":"damian","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#article","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/"},"author":{"name":"damian","@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"headline":"Tweeting with PowerShell","datePublished":"2019-07-29T17:10:17+00:00","dateModified":"2020-03-08T06:29:07+00:00","mainEntityOfPage":{"@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/"},"wordCount":571,"commentCount":0,"publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"image":{"@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/","url":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/","name":"Tweeting with PowerShell - Practical PowerShell","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg","datePublished":"2019-07-29T17:10:17+00:00","dateModified":"2020-03-08T06:29:07+00:00","breadcrumb":{"@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practicalpowershell.com\/tweeting-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#primaryimage","url":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg?fit=250%2C197&ssl=1","contentUrl":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2019\/07\/PowerShellTweet.jpg?fit=250%2C197&ssl=1","width":250,"height":197},{"@type":"BreadcrumbList","@id":"https:\/\/practicalpowershell.com\/tweeting-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practicalpowershell.com\/"},{"@type":"ListItem","position":2,"name":"Tweeting with PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/practicalpowershell.com\/#website","url":"https:\/\/practicalpowershell.com\/","name":"Practical PowerShell","description":"PowerShell books written by experts","publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/practicalpowershell.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb","name":"damian","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","caption":"damian"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":2,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/46\/revisions\/294"}],"wp:attachment":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}