CIS 216
Highline Community College
Dan Morrill
Using PowerShell to manipulate external facebook accounts
Administrative Access to the computer running Windows PowerShell
The Facebook PowerShell API at http://facebookpsmodule.codeplex.com/
Windows PowerShellA Facebook Account
Tools you will need for this
Download the Facebook PowerShell API from http://facebookpsmodule.codeplex.com/This is an alpha version code
Download the Facebook PS API
Download and extract the Facebook PowerShell Scripts to any directory:In this case I am using the download directory
on the computer I am using.
Download the software
Run the file named FacebookPSModule Alpha -.6.4.msi
Run the MSI
Install like any other software
C:\Users\dmorrill\Documents\WindowsPowerShell\Modules\Facebook\
It should install in a directory much like this oneNote this directoryIt is where you will find the scripts you need to run
this programRemember to be the administrator of your PC when
you do thisStart up Windows PowerShell ISE to run this
programStart up Windows PowerShell on the side – you
might want it
Note the directory it installs in
In regular PowerShell - Go to the directory where you installed the
Facebook API and scripts in:
Go to the directory
Before running this you need to set your execution policy Set-executionPolicy unrestrictedIt will prompt are you sure you want to do thisAnswer yes (Y)
Now you are ready to use this program
Go To PowerShell ISE
New-FBConnection: This command sets up the initial Facebook connection which you will need to use most other commands. You will only need to do this once, after that the connection will be cached in your Windows profile.
Get-FBFriend: This command retrieves the list of friends of the specified user. Note that default Facebook permissions do not permit Facebook applications to retrieve “friends of friends” lists, even though these are available from the Facebook GUI. This is a limitation of the Facebook API, not of FacebookPSModule.
The FB Connect Commands
Get-FBAlbum, Get-FBFeed, Get-FBGroup, Get-FBPhoto, Get-FBPost: These commands similarly retrieve other classes of information.
Get-FBEvent: This command retrieves the list of events of the specified user or group. Only “future” events will be retrieved, and only if the user has not explicitly responded “will not attend”.
Get-FBMember: Retrieves the list of members of a group.
Get-FBAssociation: This is a worker function for Get-FBFriends, Events and Feed, but it also provides access to other “Connections” offered by the Facebook Graph API for which specific commands are not yet available.
The FB Connect Commands
Get-FBObjectData: This retrieves data on a specific object. The object can be of any type. The –Fields parameter specifies the data to retrieve; if you do not specify this, Facebook will choose a default set of fields depending on the object type. Get-FBObjectData returns a single object with parameters corresponding to the requested fields. Individual fields may not be present on the return object if they are not specified for the Facebook object, or if you do not have permission to retrieve them. Note that most Get-FB* commands have a -Fields parameter; it is generally more efficient to retrieve them up front rather than make multiple calls to Get-FBObjectData.
Add-FBBulkPhotos: Copy multiple photos to a Facebook album*Read-FBBulkPhotos: Copy all the photos in a Facebook album to files, or all the photos in all Facebook albums
The FB Connect Commands
Add-FBBulkPhotos: Copy multiple photos to a Facebook album*Read-FBBulkPhotos: Copy all the photos in a Facebook album to files, or all the photos in all Facebook albums.
New-FBPost: Creates a new post in the user or page feed.New-FBEvent: This command creates a new Facebook event
for the current user.New-FBEventInvite: Invites users to an existing event.New-FBPhoto: Upload a photo from your computer to a
Facebook album.Show-FBMessageDialog: This command helps send bulk
Facebook messages. Facebook does not permit sending messages to be completely automated, but you can use this command to send messages with just a few clicks for each group of 50 recipients.
The FB Connect Commands
Backup-FBFriends: This reads your current friends list and backs it up to c:\temp$timestring.csv. You can analyze this file in Excel, or use import-csv and compare-object to monitor changes to your friends list over time (de-friendings etc).
Get-FBEventsFromFeed: This reads all the events from the feed for a specific owner. I use this for finding events belonging to a specific group.
Write-FBRSVPs: Read all the RSVPs for the specified event, and write them to different CSV files. Put this in a repeating Scheduled Task, and you’ll always have RSVP lists at your fingertips! This was an important scenario for my lead customer.
The FB Connect Commands
Import-Module facebook
In regular PowerShell run
Get-module –listAvailable Shows if the import was successful
Get-Command -Module Facebook
Verify the Import
Run Powershell in STA mode
Sta Starts PowerShell in single-threaded mode.
Set Execution Policy Here
Import-Module FacebookNew-FBConnection
Import and Set a new FB Connection
It is going to ask for a ton of permissions
Which then gives you this
New-FBFeed –message “this is a test, this is only a test of using Facebook at the command line”
You should see back the following if it worked right
Post a test message to make sure it works
Validate
Get-FBFriend
Now let’s have a little fun
Get a list of Friends and export to CSV
Get-fbfriend | export-csv “c:\users\administrator\my documents\FBUser.csv
Check out the file
Get a list of Facebook Friends and export to CSV
Create a post on Facebook saying Hi to your friends via the command line
Get-FBAlbum and download a pictures list – export to CSVHint get-FBAlbum | export-csv “c:\users\
administrator\my documents\album.csv” Get-Fbassociations
Hint get-FBAssociation | export….It will ask you for a kind of association, enter friend
What to do next
Get a list of all the events that a person is going to and export it as a CSV fileHint: get-FBEvent
Get a list of Events from the Facebook Feed and export it as a CSV fileHint: get-FBEventsFromFeed
Back up all your friends and save it as a CSV fileHint: backup-FBFriends
What to do next
Questions?