Tweeting from powershell
This evening, instead of hanging out at the Microsoft Dev Days Geek Night, I drove home, put the kids to bed, and sat down to figure out how to update my Twitter status from the Windows Powershell. This was inspired by the bash one-liner using curl that I learned about from Peteris Krumins’ blog (recommended). Well, it turns out not to be a one-liner in powershell, but FWIW - here's how!
function tweet([string] $status) {
#http://blogs.msdn.com/shitals/archive/2008/12/27/9254245.aspx
[System.Net.ServicePointManager]::Expect100Continue = $false
try {
$wc = new-object System.Net.WebClient
$wc.BaseAddress = "http://twitter.com"
$wc.Credentials = new-object System.Net.NetworkCredential
$wc.Credentials.UserName = "Your account name"
$wc.Credentials.Password = "password"
$stream = $wc.OpenWrite("statuses/update.xml")
$writer = new-object System.IO.StreamWriter -ArgumentList $stream
$writer.Write("status=" + $status)
}
finally {
$writer.Dispose()
$stream.Dispose()
$wc.Dispose()
}
}