Updating Facebook from Powershell!!

I was perusing my Twitter feed the other day and I noticed something interesting, a link to a codeplex project for Powershell Facebook cmdlets.  I headed over to the codeplex page and grabbed them. http://facebookpsmodule.codeplex.com/ Ater downloading the module and installing it I took a quick look under the hood.  John_msft did all the heaving lifting on these cmdlets and did a great job with documentation!

The first thing of note is that according to the documentation the commands currently have to be run through the Powershell ISE.  This is because the New-FBConnection function pops a window that authenticates you to the FB API.

In order to authenticate to the API you simply run the New-FBConnection command.


I noticed in the documentation for the Facebook cmdlets that the only Set or Add event was an Add-Event function that allows the user to create a calendar event in Facebook.

I thought it would be pretty cool to be able to update my status from Powershell.

Let me know what you think 😮


So here goes… with a slight modification to the Add-Event function that John_MSFT included in the module we come to Set-FBStatus:

<pre>function Set-FBStatus


        Set-StrictMode -Version 2.0  #Force Version 2
        trap { "Error in Set-FBStatus: $_"; break }

       $parameters = new-object 'system.collections.generic.dictionary[string,object]'  #Create new object
       $parameters["message"] = $Message
       $parameters["access_token"] = $(Get-FBConnection).AccessToken
       $raw = $(Get-FBConnection).Post("me/feed", $parameters)   #Set FB Ojbect to the $raw variable
       Convert-FBJSON $raw   #Call the Convert-FBJSON function from the Facebook cmdlets to send update

Set-FBStatus "GOD IS SOOO GOOD!  Praise him today."    #Actual Function Call</pre>

Published by ScriptWarrior

Father, Geek - Automation Evangelist with Windows Powershell

10 thoughts on “Updating Facebook from Powershell!!

  1. How long will it be before our IT departments will have FB pages that posts updates when it hits 100 Days uptime or if it has a drive down?

  2. Jeff, thanks for this! I’m working on incorporating Set-FBStatus into the base code, plus some other unrelated improvements. I appreciate the reference on the blog. A few notes on your blog post:

    You don’t have to run this though PowerShell ISE. Only the initial New-FBConnection needs to be run there (or in PowerShell.exe -STA), and it caches your access token to a file in %APPDATA%. After that you’re free to use PowerShell.exe or the PowerShell Host API.

    Regarding the comments: There are all sorts of ways to run PowerShell commands automatically, via WMI triggers, Scheduled Tasks etc. Search and you shall find…

    I’m actually “jonn_msft” (no “h”)



    1. Hey Jon,

      Thanks for the reply. Glad to provide the reference since you did most of the work on the cmdlets. I heard through the grapevine that you might be rather local. I hope to have time to dig into more development on these soon. Any ideas for other functions?


  3. I’m not sure what is “local” for you … I’m in Greater Seattle. I do have ideas, but in my experience, it’s important to start with real user scenarios, not imagined ones. For now, I’m planning to clean up the Connection / AccessToken methods, and maybe make a WIX-based installer.


  4. Feature Request:
    I see value in the following potential script

    Get-FriendofFriend | Get-Hottie | Where {$_.RelationshipStatus -eq “Single” -and $_.Age -gt 21 -and $_.Sex -eq “Female”}

    I recognize the inherit difficulty in the Get-Hottie cmdlet but I do think it would be a worthwhile endeavor.

      1. Damn. I guess that means that Zuckerberg is more short-sighted then we originally thought. LOL I do appreciate you taking a look at it. I suppose the rest is theoretically possible. I personally have little need of said script but I’m sure there are lots of powershell geeks out there wondering if one of their facebook friends has a hot sister that they didn’t know about. 🙂

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: