PowerShell でFinancialForce Data データをCSV に落としてみた

標準PowerShell cmdlets を使ってFinancialForce テーブルにアクセス。

CData Cmdlets Module for FinancialForce は、直感的なFinancialForce データ連携を提供する標準cmdlet です。 本記事では、FinancialForce Cmdlets を使ったサンプルを提供します。

Creating a Connection to Your FinancialForce Data

There are several authentication methods available for connecting to FinancialForce: login credentials, SSO, and OAuth.

Authenticating with a Login and Token

Set the User and Password to your login credentials. Additionally, set the SecurityToken. By default, the SecurityToken is required, but you can make it optional by allowing a range of trusted IP addresses.

To disable the security token:

  1. Log in to FinancialForce and enter "Network Access" in the Quick Find box in the setup section.
  2. Add your IP address to the list of trusted IP addresses.

To obtain the security token:

  1. Open the personal information page on FinancialForce.com.
  2. Click the link to reset your security token. The token will be emailed to you.
  3. Specify the security token in the SecurityToken connection property or append it to the Password.

Authenticating with OAuth

If you do not have access to the user name and password or do not want to require them, use the OAuth user consent flow. See the OAuth section in the Help for an authentication guide.

Connecting to FinancialForce Sandbox Accounts

Set UseSandbox to true (false by default) to use a FinancialForce sandbox account. Ensure that you specify a sandbox user name in User.

$conn = Connect-FinancialForce  -User "$User" -Password "$Password" -Security Token "$Security Token"

Selecting Data

Follow the steps below to retrieve data from the Account table and pipe the result into to a CSV file:

Select-FinancialForce -Connection $conn -Table Account | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myAccountData.csv -NoTypeInformation

You will notice that we piped the results from Select-FinancialForce into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.

Deleting Data

The following line deletes any records that match the criteria:

Select-FinancialForce -Connection $conn -Table Account -Where "Industry = Floppy Disks" | Remove-FinancialForce

Inserting and Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into FinancialForce, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyAccountUpdates.csv | %{
  $record = Select-FinancialForce -Connection $FinancialForce -Table Account -Where ("Id = `'"+$_.Id+"`'")
    Update-FinancialForce -Connection $financialforce -Table Account -Columns ("BillingState","Name") -Values ($_.BillingState, $_.Name) -Where ("Id = `'"+$_.Id+"`'")
    Add-FinancialForce -Connection $financialforce -Table Account -Columns ("BillingState","Name") -Values ($_.BillingState, $_.Name)

As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!