Hi,
In the world of Powershell everything Blue. Powershell community is fill with lots of amazing thinkers, developers and contributors. There are lots of nice peoples who spend day and night on writing a script and then give them to the community to use it freely. There are lots of other peoples too who are very active on Powershell Forms , you just need to as a question and i am sure that you will hear from any of them soon.
One the module i like in powershell is “Facebook Powershell Module” which are created by “
Jon Newman”.
The first question came in mind why to use this module? and the Answer is, It is Cool, it is geeky and it is more then a module.
lets think about a scenario, for example.
- You can write a simple script which contain a list of all of your friends birthday date and that script run everyday,and using Facebook module you can wish them on their Facebook account and you never miss anyone birthday.
- If you are running a group , page and love to share “Quote of the Day”, then create a list of 365 quotes and post them automatically using Facebook module.
- If your wife /girlfriend is angry with you and complaining that you don't give her time, to impress her just collect few love quotes and post it on her wall in every one hour ;o)
Powershell is all about automation, lets automate the Facebook. ;o)
I am using a Facebook module to post a message on my Facebook wall when any of my server fails. Logically we created a new Facebook account for this and we added that Facebook account as friend {all IT admins}, and there are few scripts which runs every night and in case they found anything worn they post a message on their walls and in the morning we all can see it.
Lets Start.
You can download the module from this link “
http://facebookpsmodule.codeplex.com/” and the current version of module is “
FacebookPSModule Alpha 0.6.3” .
Download the module and save it on your desktop.
this is a zip file extract it and run the “FacebookPsModule Aplha 0.6.3.msi”
A welcome window will be open “Click on Next”
The default folder to save the module file in “WindowsPowershell” located in My Document or Documents, Leave it as it is and click on “Next”
Installation starts.
Installation Complete , click on “Close”
You can verify that Facebook Module has copied to the
“Documents\WindowsPowershell\Module\Facebook “
Now lets open powershell and import the module.
Import-Module facebook
and let’s see which comdlets it has.
Get-Command -Module Facebook
Wow!!!!!
Let run the Cmdlet New-Connection to connect to the Facebook …
New-FBConnection
errr, error ….
The New-FBConnection cmdlet runs only in STA mode, you have to do this one .
Lets run Powershell in STA mode.
Open Run and type “Powershell.exe –STA” and click on OK.
when powershell windows open. Import Facebook Module once again and run New-FBConnection
when you run the New-FBConnection cmdlet a Facebook login windows will open.
Now provide your Email ID and password and make sure that you checked on “Keep me logged in” and then click on “Log In”
and now a Facebook app page will open , click on “Log in With Facebook”
Now the module is ask for Permission and just click on “Allow”.
after you clicked on allow, all is done and you will see this . that means connection with your Facebook account is successful.
we have to enter these Login Details once only { i tested this with multiple reboots of my machine i am able to access the Facebook account without enter user credentials } , as per Facebook Module documentation,,
“Once you create an “access token”, it will by default be cached in %LOCALAPPDATA%\FacebookPowerShellModule_CachedToken.txt, so you will not have to re-enter it as long as you use your current user account.”
Okeis. now lets test it. using
New-FBFeed cmdlet.
New-FBFeed -Message "this is a test message"
and the result is.
Bingo Now next step it to automate it.
i wrote a simple script to test it .
This script Import Facebook Module first, and it will test the connectivity of all the servers those are defined in $servers and if the connection to the server is successful it just wrote and message in the console and it the connection is unsuccessful then it wrote on Facebook Wall.
Import-Module Facebook
New-FBConnection
$servers = "Dc-local","Not-Exists"
foreach ( $server in $servers ) {
if (test-Connection -ComputerName $Server -Count 2 -Quiet ) {
write-Host "$Server is alive and Pinging " -ForegroundColor Green
} else
{
New-FBFeed -Message "$Server seems dead not pinging"
}
}
When i run the script the output was below. My Dc-Local is live and Not-Exists is not so the below output is showing me the Facebook FeedID
Now lets check the Facebook wall.
Yo!! Our server was not reachable and we sucessfully posted that message to the Wall..
We successfully automated the Facebook using powershell.
Thanks
Aman Dhally