30
CIS 216 Highline Community College Dan Morrill Using PowerShell to manipulate external facebook accounts

Using power shell to manipulate external facebook accounts

Embed Size (px)

Citation preview

Page 1: Using power shell to manipulate external facebook accounts

CIS 216

Highline Community College

Dan Morrill

Using PowerShell to manipulate external facebook accounts

Page 2: Using power shell 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

Page 3: Using power shell to manipulate external facebook accounts

Download the Facebook PowerShell API from http://facebookpsmodule.codeplex.com/This is an alpha version code

Download the Facebook PS API

Page 4: Using power shell to manipulate external facebook accounts

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

Page 5: Using power shell to manipulate external facebook accounts

Run the file named FacebookPSModule Alpha -.6.4.msi

Run the MSI

Page 6: Using power shell to manipulate external facebook accounts

Install like any other software

Page 7: Using power shell to manipulate external facebook accounts

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

Page 8: Using power shell to manipulate external facebook accounts

In regular PowerShell - Go to the directory where you installed the

Facebook API and scripts in:

Go to the directory

Page 9: Using power shell to manipulate external facebook accounts

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

Page 10: Using power shell to manipulate external facebook accounts

Go To PowerShell ISE

Page 11: Using power shell to manipulate external facebook accounts

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

Page 12: Using power shell to manipulate external facebook accounts

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

Page 13: Using power shell to manipulate external facebook accounts

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

Page 14: Using power shell to manipulate external facebook accounts

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

Page 15: Using power shell to manipulate external facebook accounts

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

Page 16: Using power shell to manipulate external facebook accounts

Import-Module facebook

In regular PowerShell run

Page 17: Using power shell to manipulate external facebook accounts

Get-module –listAvailable Shows if the import was successful

Get-Command -Module Facebook

Verify the Import

Page 18: Using power shell to manipulate external facebook accounts

Run Powershell in STA mode

Sta Starts PowerShell in single-threaded mode.

Page 19: Using power shell to manipulate external facebook accounts

Set Execution Policy Here

Page 20: Using power shell to manipulate external facebook accounts

Import-Module FacebookNew-FBConnection

Import and Set a new FB Connection

Page 21: Using power shell to manipulate external facebook accounts

It is going to ask for a ton of permissions

Page 22: Using power shell to manipulate external facebook accounts

Which then gives you this

Page 23: Using power shell to manipulate external facebook accounts

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

Page 24: Using power shell to manipulate external facebook accounts

Validate

Page 25: Using power shell to manipulate external facebook accounts

Get-FBFriend

Now let’s have a little fun

Page 26: Using power shell to manipulate external facebook accounts

Get a list of Friends and export to CSV

Get-fbfriend | export-csv “c:\users\administrator\my documents\FBUser.csv

Page 27: Using power shell to manipulate external facebook accounts

Check out the file

Page 28: Using power shell to manipulate external facebook accounts

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

Page 29: Using power shell to manipulate external facebook accounts

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

Page 30: Using power shell to manipulate external facebook accounts

Questions?