<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>youdidwhatwithtsql.com &#187; automating internet explorer</title>
	<atom:link href="http://www.youdidwhatwithtsql.com/tag/automating-internet-explorer/feed" rel="self" type="application/rss+xml" />
	<link>http://www.youdidwhatwithtsql.com</link>
	<description>making DBAs everywhere curse!</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:21:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Automating Internet Explorer with Powershell</title>
		<link>http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467</link>
		<comments>http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467#comments</comments>
		<pubDate>Fri, 18 Dec 2009 16:03:30 +0000</pubDate>
		<dc:creator>Rhys</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[automating internet explorer]]></category>
		<category><![CDATA[completely pointless]]></category>

		<guid isPermaLink="false">http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467</guid>
		<description><![CDATA[Ashamed of the amount of time you spend on Twitter? Want to know how to automate Internet Explorer with Powershell? Once again Powershell comes to the rescue! Here&#8217;s an illustration I came up with to post tweets on your twitter account from a text file. Create a text file called tweets.txt and place it into [...]<p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467">Automating Internet Explorer with Powershell</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Ashamed of the amount of time you spend on <a href="http://twitter.com" target="_blank">Twitter</a>? Want to know how to automate Internet Explorer with <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a>? Once again <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target="_blank">Powershell</a> comes to the rescue! Here&#8217;s an illustration I came up with to post tweets on your twitter account from a text file.</p>
<p>Create a text file called <strong>tweets.txt</strong> and place it into your user profile directory (this will be something like <strong>C:\Users\&lt;username&gt; </strong>on Vista and Windows 7 or <strong>C:\Documents and Settings\&lt;username&gt; </strong>on Windows XP). Here&#8217;s what I placed in mine;</p>
<pre>Getting my head down with a little Powershell to automate IE.
Heavy snow expected over South East England tonight. Black sludge in London to follow.
Must get myself a nice warm hat.
Last Friday before Xmas. Farringdon will be rammed tonight with the usual Fabric crowd.
Going downstairs for a swim.</pre>
<p>Next you need to modify a few variables in the Powershell script below.</p>
<p><strong></strong></p>
<p><strong>$username_or_email</strong> &#8211; Your twitter username or account email address. </p>
<p><strong>$password</strong> &#8211; Your twitter password.</p>
<p><strong>$sleep</strong> &#8211; The interval you want between tweets.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p467code2'); return false;">View Code</a> POWERSHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4672"><td class="code" id="p467code2"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Author: Rhys Campbell</span>
<span style="color: #008000;"># Date: 18/12/2009</span>
<span style="color: #008000;"># Powershell script to automate Internet Explorer</span>
<span style="color: #008000;"># to post tweets to your Twitter account</span>
&nbsp;
<span style="color: #008000;"># Twitter login name or email</span>
<span style="color: #800080;">$username_or_email</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;xxxxxxxxxxxxxxxx&quot;</span>;
<span style="color: #008000;"># Your twitter password</span>
<span style="color: #800080;">$password</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;xxxxxxxxxxxx&quot;</span>;
<span style="color: #800080;">$url</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;http://twitter.com/login&quot;</span>;
&nbsp;
<span style="color: #008000;"># txt file containing 1 tweet per line</span>
<span style="color: #800080;">$tweets</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #800000;">&quot;$env:USERPROFILE\tweets.txt&quot;</span>;
<span style="color: #008000;">#Interval between tweets</span>
<span style="color: #800080;">$sleep</span> <span style="color: pink;">=</span> <span style="color: #804000;">60</span>; 
&nbsp;
<span style="color: #008000;"># This is just an attempt to handle the situation where you are already logged into twitter</span>
<span style="color: #0000FF;">trap</span> <span style="color: #000000;">&#91;</span>Exception<span style="color: #000000;">&#93;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># This will happen if you're already logged in</span>
	<span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Exception.Message <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;Property 'value' cannot be found on this object; make sure it exists and is settable.&quot;</span> <span style="color: #FF0000;">-Or</span> <span style="color: #000080;">$_</span>.Exception.Message <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;You cannot call a method on a null-valued expression.&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Try and skip this error</span>
		<span style="color: #0000FF;">continue</span>;
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Fail for other Exceptions</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red <span style="color: #000080;">$_</span>.Exception.Message;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Create an ie com object</span>
<span style="color: #800080;">$ie</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: pink;">-</span>com internetexplorer.application;
<span style="color: #800080;">$ie</span>.visible <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>;
<span style="color: #800080;">$ie</span>.navigate<span style="color: #000000;">&#40;</span><span style="color: #800080;">$url</span><span style="color: #000000;">&#41;</span>;
<span style="color: #008000;"># Wait for the page to load</span>
<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$ie</span>.Busy <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Milliseconds</span> <span style="color: #804000;">1000</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Login to twitter</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green <span style="color: #800000;">&quot;Attempting to login to Twitter.&quot;</span>;
<span style="color: #008000;"># Add login details</span>
<span style="color: #800080;">$ie</span>.Document.getElementById<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;username_or_email&quot;</span><span style="color: #000000;">&#41;</span>.value <span style="color: pink;">=</span> <span style="color: #800080;">$username_or_email</span>;
<span style="color: #800080;">$ie</span>.Document.getElementById<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;session[password]&quot;</span><span style="color: #000000;">&#41;</span>.value <span style="color: pink;">=</span> <span style="color: #800080;">$password</span>;
<span style="color: #008000;"># Click the submit button</span>
<span style="color: #800080;">$ie</span>.Document.getElementById<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;signin_submit&quot;</span><span style="color: #000000;">&#41;</span>.Click<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #008000;"># Wait for the page to load</span>
<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$ie</span>.Busy <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Milliseconds</span> <span style="color: #804000;">1000</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Loop through each tweet in the txt file</span>
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$tweet</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$tweets</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$ie</span>.Document.getElementById<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;status&quot;</span><span style="color: #000000;">&#41;</span>.value <span style="color: pink;">=</span> <span style="color: #800080;">$tweet</span>;
	<span style="color: #800080;">$ie</span>.Document.getElementById<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;status_update_form&quot;</span><span style="color: #000000;">&#41;</span>.Submit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green <span style="color: #800000;">&quot;Tweeted; $tweet.&quot;</span>;
	<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #800080;">$sleep</span>;
	<span style="color: #008000;"># Check to see if ie is still busy and sleep if so</span>
	<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$ie</span>.Busy <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Milliseconds</span> <span style="color: #804000;">1000</span>;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Execute the Powershell script and get tweeting! Here&#8217;s my output from a test run;</p>
<pre>Attempting to login to Twitter.
Tweeted; Getting my head down with a little Powershell to automate IE..
Tweeted; Heavy snow expected over South East England tonight. Black sludge in London to follow..
Tweeted; Must get myself a nice warm hat..
Tweeted; Last Friday before Xmas. Farringdon will be rammed tonight with the usual Fabric crowd..
Tweeted; Going downstairs for a swim..</pre>
<p>Please be aware that changes Twitter make to their site may break this script so it may not function for long without changes. If you want to know more about working with IE and Powershell check out this <a href="http://blogs.technet.com/heyscriptingguy/archive/tags/Windows+PowerShell/Internet+Explorer/default.aspx" target="_blank">link</a> and follow <a href="http://twitter.com/ScriptingGuys" target="_blank">@ScriptingGuys</a> on twitter.</p>
<p><map name='google_ad_map_467_a45beff5d2e172f6'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/467?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_467_a45beff5d2e172f6' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=467&amp;url=http%3A%2F%2Fwww.youdidwhatwithtsql.com%2Fautomating-internet-explorer-with-powershell%2F467' title="Automating Internet Explorer with Powershell" alt=" Automating Internet Explorer with Powershell" /></p><p>Post from: <a href="http://www.youdidwhatwithtsql.com">youdidwhatwithtsql.com</a><br/><br/><a href="http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467">Automating Internet Explorer with Powershell</a></p>
<div class="none"><div class="g-plusone" data-href="http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467" size="standard" count="true"></div></div>]]></content:encoded>
			<wfw:commentRss>http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

