For some reason your Powershell script should send a Tweet. With this function Powershell will send a message to Twitter.
function Send-Tweet($Message)
{
#Twitter Login
$Twitter_UserName = "yourname"
$Twitter_Password = "yourpassword"
$Twitter_URL = "https://twitter.com/statuses/update.xml?status="
$Twitter_Request = [System.Net.WebRequest]::Create($Twitter_URL + $Message)
$Twitter_Request.credentials= New-Object System.Net.NetworkCredential($Twitter_UserName,$Twitter_Password)
$Twitter_Request.method= "POST"
$Twitter_Request.contentType = "application/x-www-form-urlencoded"
$Twitter_Request.GetResponse().statusCode # return the status code of the request
}
You can now call this function and add a message
Send-Tweet "This is my first Tweet from Powershell"
If you need a interactive script you can simply use this (seen by Bhargav’s IT Playground)
function Send-Tweet($Message,$UserName){
if($Message-eq$null){$Message=Read-Host"Enter your tweet"}
if($Username-eq$null){$Username=read-host"Enter your twitter username"}
if($Password-eq$null)
{
$Password=read-host-assecurestring"Enter your twitter password"
$marshal=[Runtime.InteropServices.Marshal]
$Password=$marshal::PtrToStringAuto($marshal::SecureStringToBSTR($Password))
}
$url="https://twitter.com/statuses/update.xml?status=$Message"
$request=[System.Net.WebRequest]::Create($url)
$request.credentials=New-Object System.Net.NetworkCredential($UserName,$Password)
$request.method="POST"
$request.contentType ="application/x-www-form-urlencoded"
$request.GetResponse().statusCode # return the status code of the request}
da hemmers ja :) super! i versuch das mal einzubinden :)
da hemmers ja :) super! i versuch das mal einzubinden :)
The remote server returned an error: (401) Unauthorized using my twitter username & password…
This script is returning OK but when I see at my Twitter account, I can’t see any tweet. Pleaes help me if any other configuration is required.