Tweet with PowerShell   Leave a comment

I wanted to type “tweet <Blah>” from a Powershell session and have it appear in my tweet stream, nothing fancy right?

 – Mine has to go through an authenticating proxy, so there’s a bit of script for that also, you could store the credentials in file, which saves typing them in, but that’s for another time.

OK, so here’s how you do that.

There are proably a hundred way to do this, here’ s the one I used.

(I will be adding a suitable code display add-in, once someone shows me how!)

So – first step, slap this code in your $profile (notepad $profile) for a PS prompt.

Second step is after the script, but you need to do that first to get your twit codes which you will need to *insert* into this script.  You also will need to download the API assemblies and make them available in your script dir, I’ll provide links.

[Reflection.Assembly]::LoadFile(“c:\Scripts\DLLs\Twitterizer2.dll”) > $null
[Reflection.assembly]::LoadFile(“c:\Scripts\DLLs\Newtonsoft.Json.dll”) > $null
 $cred = Get-Credential
$tokens = New-Object Twitterizer.OAuthTokens;
$options = New-Object Twitterizer.StatusUpdateOptions
$proxy = New-Object System.Net.WebProxy
$proxy.Address = “
$proxy.Credentials = $cred.GetNetworkCredential()
# $proxy.UseDefaultCredentials = $true
$options.Proxy = $proxy
$tokens.AccessToken = “***************your access token stuff****************”
$tokens.AccessTokenSecret = “***your access token secretf*********************”
$tokens.ConsumerKey = “*********your consumer key *****”
$tokens.ConsumerSecret = “****************your secret ****************”
 function Tweet($cheese)
$global:f = [Twitterizer.TwitterStatus]::Update($tokens,$cheese,$options);
                if ($($result = $f.Result) -eq $result.Success)
Write-Host “Successful Tweet…”
} else
Write-Host “Fail, Epic..Fail Whale…no Tweet…”

Posted September 16, 2011 by stormwalker255 in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: