Skip to content

Command Reference

ubraig edited this page May 10, 2024 · 2 revisions

Add-SfRecords

ALIAS

sfinsert

NAME

Add-SfRecords

SYNOPSIS

Invokes Salesforce Data Loader with an INSERT operation to create records from a '.csv' file.

SYNTAX

Add-SfRecords [-SfAuthToken] <Hashtable> [-Object] <String> [[-Path] <String>] [-MappingFile <String>] [-Bulk <String>] [-BatchSize <Int32>] [<CommonParameters>]

DESCRIPTION

Reads records from a .csv file and INSERTs those to the org that is represented by the AuthToken.

The format of the .csv file is defined as: UTF-8 encoding, without BOM, comma (,) as separator.
For more details see https://github.com/ubraig/sf-dataloader-cli/wiki/about-csv-files

If no mapping file ist given, a default mapping file will be derived from the column headers in the .csv file. 
See ConvertTo-SfMappingFile for details on this behaviour.

PARAMETERS

-SfAuthToken <Hashtable>
    Hashmap as provided by Get-SfAuthToken command.
    
-Object <String>
    API name of the sObject/entity.
    
-Path <String>
    Path and filename of the input .csv file. 
    Needs to include the '.csv' extension.
    If no file name is provided, it will look for the default name "<Object>.csv" in the current directory.
    
-MappingFile <String>
    Path and filename of the '.sdl' mapping file. 
    If empty, a default mapping file will be created on the fly based on the column names in the input .csv file.
    
-Bulk <String>
    'Serial'   : Use BULK API in serial mode.
    'Parallel' : Use BULK API in parallel mode.
    Default if not given is SOAP API.
    
-BatchSize <Int32>
    Default used for SOAP API: 200.
    Default used for BULK API: 2000.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

REMARKS

To see the examples, type: "Get-Help Add-SfRecords -Examples"
For more information, type: "Get-Help Add-SfRecords -Detailed"
For technical information, type: "Get-Help Add-SfRecords -Full"
For online help, type: "Get-Help Add-SfRecords -Online"

ConvertTo-SfEncryptedString

NAME

ConvertTo-SfEncryptedString

SYNOPSIS

Encrypts a string (either provided via command line parameter or prompted via console input) based on the key file provided.

SYNTAX

ConvertTo-SfEncryptedString [-KeyFile] <String> [-Prompt <String>] [<CommonParameters>]

ConvertTo-SfEncryptedString [-KeyFile] <String> -StringToEncrypt <String> [<CommonParameters>]

DESCRIPTION

PARAMETERS

-KeyFile <String>
    Path to the key file. The file must already exist.
    
-StringToEncrypt <String>
    String that is to be encrypted.
    If empty, user will be prompted for console input.
    
-Prompt <String>
    Prompt for secure input. If not provided, a default prompt will be used.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

EXAMPLE 1

PS>New-SfEncryptionKeyFile -Path MyKeyFile.key
PS>ConvertTo-SfEncryptedString -KeyFile MyKeyFile.key -StringToEncrypt 'MyUnencryptedPassword'

Will return the encrypted password to the console. This string then can be safely stored in scripts in order
to be used as parameter -EncryptedString in command Get-SfAuthToken.

EXAMPLE 2

PS>New-SfEncryptionKeyFile -Path MyKeyFile.key
PS>ConvertTo-SfEncryptedString -KeyFile MyKeyFile.key -Prompt 'Enter password + security token'

Will prompt the user for secure console input, i.e. string entered will not show up on the screen.
Will return the encrypted password string to the console. This string then can be safely stored in scripts in order
to be used as parameter -EncryptedString in command Get-SfAuthToken.

EXAMPLE 3

PS>New-SfEncryptionKeyFile -Path MyKeyFile.key
PS>$MyEncryptedPassword = ConvertTo-SfEncryptedString -KeyFile MyKeyFile.key -Prompt 'Enter password + security token'
PS>$MyOrg = Get-SfAuthToken MyUserName@MyOrg.de -EncryptedString $MyEncryptedPassword -InstanceUrl https://test.salesforce.com -KeyFile .\MyKeyFile.key

Will prompt the user for secure console input, i.e. string entered will not show up on the screen.
Will then create an Auth token from it for the given user in the Sandbox.

REMARKS

To see the examples, type: "Get-Help ConvertTo-SfEncryptedString -Examples"
For more information, type: "Get-Help ConvertTo-SfEncryptedString -Detailed"
For technical information, type: "Get-Help ConvertTo-SfEncryptedString -Full"
For online help, type: "Get-Help ConvertTo-SfEncryptedString -Online"

ConvertTo-SfFieldList

NAME

ConvertTo-SfFieldList

SYNOPSIS

Takes a list (array) of field names converts to a comma-separated list to be used in a SOQL statement.
Fields with a comment prefix of '#' will be removed.

SYNTAX

ConvertTo-SfFieldList [-FieldNames] <String[]> [<CommonParameters>]

DESCRIPTION

PARAMETERS

-FieldNames <String[]>
    List of field names as PowerShell string array, e.g. @('Id', 'FirstName', 'LastName').
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

EXAMPLE 1

PS>$MyContactFields = @('Id', '#FirstName', 'LastName', 'Account.Name', 'MyCustomField__c')
PS>$MyFieldList = ConvertTo-SfFieldList $MyContactFields
PS>$MySoqlSelect = "SELECT $MyFieldList FROM Contact"

Will result to the following value in $MySoqlSelect:
SELECT Id, LastName, Account.Name, MyCustomField__c FROM Contact

REMARKS

To see the examples, type: "Get-Help ConvertTo-SfFieldList -Examples"
For more information, type: "Get-Help ConvertTo-SfFieldList -Detailed"
For technical information, type: "Get-Help ConvertTo-SfFieldList -Full"
For online help, type: "Get-Help ConvertTo-SfFieldList -Online"

ConvertTo-SfMappingFile

NAME

ConvertTo-SfMappingFile

SYNOPSIS

Takes a list (array) of field names and converts to a default field mapping in a .sdl mapping file.

SYNTAX

ConvertTo-SfMappingFile [-Fields] <String[]> [-Path] <String> [<CommonParameters>]

DESCRIPTION

Each UPDATE, INSERT, UPSERT operation requires a .sdl mapping file that maps the field name (column header) of
the .csv file to the API name of the field in the target org.
In cases where the field names in the .csv are same as the API names, i.e. where a 1:1 mapping is needed,
such mapping can be created automatically by this command. See examples.

Field names with a prefix of '#' will be included in the .sdl and, by definition, are treated as comment line.

The dot notation in field names from child-to-parent relationships queries will be converted as
required by .sdl syntax, e.g. 'MyCustomLookup__r.Name' will be converted to 'MyCustomLookup__r\:Name'.

PARAMETERS

-Fields <String[]>
    List of field names as PowerShell string array, e.g. @('Id', 'FirstName', 'LastName').
    
-Path <String>
    Path to the '.sdl' mapping file to be created.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

EXAMPLE 1

PS>$MyContactFields = @('Id', '#FirstName', 'LastName', 'Account.Name', 'MyCustomField__c')
PS>ConvertTo-SfMappingFile $MyContactFields MyContactMapping.sdl

Will result to a mapping file 'MyContactMapping.sdl' that looks like
  Id=Id
  #FirstName=#FirstName
  LastName=LastName
  Account.Name=Account\:Name
  MyCustomField__c=MyCustomField__c

REMARKS

To see the examples, type: "Get-Help ConvertTo-SfMappingFile -Examples"
For more information, type: "Get-Help ConvertTo-SfMappingFile -Detailed"
For technical information, type: "Get-Help ConvertTo-SfMappingFile -Full"
For online help, type: "Get-Help ConvertTo-SfMappingFile -Online"

Export-SfRecords

ALIAS

sfextract

NAME

Export-SfRecords

SYNOPSIS

Invokes Salesforce Data Loader for a QUERY (EXTRACT) operation that exports data to a .csv file.

SYNTAX

Export-SfRecords [-SfAuthToken] <Hashtable> [-Object] <String> [[-Soql] <String>] [[-Path] <String>] [-ExtractAll] [-Bulk <String>] [-BatchSize <Int32>] [<CommonParameters>]

DESCRIPTION

Executes the SOQL SELECT statement as provided and writes the result to a .csv file.

The format of the .csv file is defined as: UTF-8 encoding, without BOM, comma (,) as separator.
For more details see https://github.com/ubraig/sf-dataloader-cli/wiki/about-csv-files

PARAMETERS

-SfAuthToken <Hashtable>
    Hashmap as provided by Get-SfAuthToken command.
    
-Object <String>
    API name of the sObject/entity.
    
-Soql <String>
    A complete SOQL statement.
    If no SELECT statement is given, it will default to "SELECT Id FROM <Object>".
    The SELECT statement may include WHERE, ORDER BY and LIMIT clauses.
    
-Path <String>
    Path and filename of the output csv file. Needs to include the '.csv' extension.
    
-ExtractAll [<SwitchParameter>]
    
-Bulk <String>
    'Serial'   : Use BULK API in serial mode.
    'Parallel' : Use BULK API in parallel mode.
    Default if not given is SOAP API.
    
-BatchSize <Int32>
    Default used for SOAP API: 200.
    Default used for BULK API: 2000.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

EXAMPLE 1

PS>$MyOrg = Get-SfAuthToken -BrowserLogin Sandbox
PS>Export-SfRecords $MyOrg Lead "SELECT Id, FirstName, LastName, Company FROM Lead" MyLeads.csv

Will open a browser window that asks to confirm the code and then asks for user name + password.
Then exports Lead records to the MyLeads.csv file.

REMARKS

To see the examples, type: "Get-Help Export-SfRecords -Examples"
For more information, type: "Get-Help Export-SfRecords -Detailed"
For technical information, type: "Get-Help Export-SfRecords -Full"
For online help, type: "Get-Help Export-SfRecords -Online"

Get-SfAuthToken

ALIAS

sfauth

NAME

Get-SfAuthToken

SYNOPSIS

Offers various options to authorize an Org in order to get an AuthToken suitable for Data Loader.

SYNTAX

Get-SfAuthToken [[-OrgAliasOrUsername] <String>] [-KeyFile <String>] [<CommonParameters>]

Get-SfAuthToken [-Username] <String> -ConsoleInput [-KeyFile <String>] -InstanceUrl <String> [<CommonParameters>]

Get-SfAuthToken [-Username] <String> [-EncryptedString] <String> -KeyFile <String> -InstanceUrl <String> [<CommonParameters>]

Get-SfAuthToken -BrowserLogin <String> [<CommonParameters>]

DESCRIPTION

Each command that calls Data Loader requires an AuthToken as the first parameter.
Technically, the token is a HashTable with name/value pairs ready to be used in the ConfigMap in Data Loader.
If SFDX is installed, the authorizations from SFDX can be used.

PARAMETERS

-OrgAliasOrUsername <String>
    SFDX OrgAlias or Username.
    If empty, the SFDX default setting will be used.
    
-Username <String>
    Salesforce Username
    
-EncryptedString <String>
    Encrypted password + security token.
    
-ConsoleInput [<SwitchParameter>]
    Ask password and, if necessary, security token securely from user.
    
-KeyFile <String>
    Path to an existing key file that is to be used.
    If empty, a default key file will be generated and used.
    If the default key file already exists, it will be re-used.
    Mandatory in case an encrypted password is given.
    
-BrowserLogin <String>
    Open a Browser window to enter username and password. Need to provide type of environment: Sandbox | Production
    
-InstanceUrl <String>
    Instance URL of the Org, e.g.
    - https://test.salesforce.com for sandbox 
    - https://login.salesforce.com for production, or
    - the MyDomain URL.
    = 'https://test.salesforce.com'
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

EXAMPLE 1

PS>$MyOrg = Get-SfAuthToken

Uses the oauth token of the default org as set in SFDX.
See 'sfdx org display' command.

EXAMPLE 2

PS>$MyOrg = Get-SfAuthToken MySfdxOrgAlias

Uses the oauth token of the  org 'MySfdxOrgAlias' as set in SFDX.
See 'sfdx auth list' command for more details.

EXAMPLE 3

PS>$MyOrg = Get-SfAuthToken MyUserName@MyOrg.de -ConsoleInput -InstanceUrl https://test.salesforce.com

Will ask for the password via secure input and prepare credential for sandbox URL.

EXAMPLE 4

PS>$MyOrg = Get-SfAuthToken MyUserName@MyOrg.de -EncryptedString 'MyEncryptedPwdAndSecToken' -InstanceUrl https://test.salesforce.com -KeyFile .\MyKeyFile.key

Take the password (and security token) that has already been encrypted with MyKeyFile.key and prepare credential for sandbox URL.
See New-SfEncryptionKeyFile and ConvertTo-SfEncryptedString for more details.

EXAMPLE 5

PS>$MyOrg = -BrowserLogin Sandbox

Will create a placeholder token.
Each time it is used for calling Data Loader, a browser window will open and ask for username/password.

REMARKS

To see the examples, type: "Get-Help Get-SfAuthToken -Examples"
For more information, type: "Get-Help Get-SfAuthToken -Detailed"
For technical information, type: "Get-Help Get-SfAuthToken -Full"
For online help, type: "Get-Help Get-SfAuthToken -Online"

Get-SfFieldNames

NAME

Get-SfFieldNames

SYNOPSIS

Collects a list of field names from various source file formats and returns as a list (array) of field names.

SYNTAX

Get-SfFieldNames [-Path] <String> [[-Converter] <String>] [<CommonParameters>]

DESCRIPTION

PARAMETERS

-Path <String>
    Source file to extract field names from.
    
-Converter <String>
    Name of the converter to be applied in order to get the field name list.
    If none is given, the file extension is used.
    txt
    	A plain text file with a field name in each line.
    	Lines starting with '#' will be ignored.
    csv
    	First line in the file will be interpreted as column names.
    	Column names starting with '#' will be ignored.
    sdl
    	A dataloader mapping file (.sdl) with a dataloader mapping entry on each line.
    	The part left of the '=' will be used as field name.
    	Lines without a '=' will be ignored.
    	Lines starting with '#' will be ignored.
    sdlRightSide
    	A dataloader mapping file (.sdl) with a dataloader mapping entry on each line.
    	The part right of the '=' will be used as field name.
    	Lines without a '=' will be ignored.
    	Lines starting with '#' will be ignored.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

REMARKS

To see the examples, type: "Get-Help Get-SfFieldNames -Examples"
For more information, type: "Get-Help Get-SfFieldNames -Detailed"
For technical information, type: "Get-Help Get-SfFieldNames -Full"
For online help, type: "Get-Help Get-SfFieldNames -Online"

Import-SfRecords

ALIAS

sfupsert

NAME

Import-SfRecords

SYNOPSIS

Invokes Salesforce Data Loader with an UPSERT operation to create/update records from a '.csv' file.

SYNTAX

Import-SfRecords [-SfAuthToken] <Hashtable> [-ExternalIdField <String>] [-Object] <String> [[-Path] <String>] [-MappingFile <String>] [-Bulk <String>] [-BatchSize <Int32>] [<CommonParameters>]

DESCRIPTION

Reads records from a .csv file and UPSERTs those to the org that is represented by the AuthToken.
The name of the External ID field to be used needs to be provided.

If no filename is given, it is derived from the object to be imported: "<Object>.csv".
The format of the .csv file is defined as: UTF-8 encoding, without BOM, comma (,) as separator.
For more details see https://github.com/ubraig/sf-dataloader-cli/wiki/about-csv-files

If no mapping file ist given, a default mapping file will be derived from the column headers in the .csv file. 
See ConvertTo-SfMappingFile for details on this behaviour.

PARAMETERS

-SfAuthToken <Hashtable>
    Hashmap as provided by Get-SfAuthToken command.
    
-Object <String>
    API name of the sObject/entity.
    
-ExternalIdField <String>
    API name of the field to be used as External ID field during UPSERT operation.
    
-Path <String>
    Path and filename of the input .csv file. 
    Needs to include the '.csv' extension.
    If no file name is provided, it will look for the default name "<Object>.csv" in the current directory.
    
-MappingFile <String>
    Path and filename of the '.sdl' mapping file. 
    If empty, a default mapping file will be created on the fly based on the column names in the input .csv file.
    
-Bulk <String>
    'Serial'   : Use BULK API in serial mode.
    'Parallel' : Use BULK API in parallel mode.
    Default if not given is SOAP API.
    
-BatchSize <Int32>
    Default used for SOAP API: 200.
    Default used for BULK API: 2000.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

REMARKS

To see the examples, type: "Get-Help Import-SfRecords -Examples"
For more information, type: "Get-Help Import-SfRecords -Detailed"
For technical information, type: "Get-Help Import-SfRecords -Full"
For online help, type: "Get-Help Import-SfRecords -Online"

New-SfEncryptionKeyFile

NAME

New-SfEncryptionKeyFile

SYNOPSIS

Creates a new encryption key file.

SYNTAX

New-SfEncryptionKeyFile [-Path] <String> [-KeepExisting] [<CommonParameters>]

DESCRIPTION

PARAMETERS

-Path <String>
    Key file to create.
    
-KeepExisting [<SwitchParameter>]
    If encryption key file of same name is already existing, keep it untouched.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

EXAMPLE 1

PS>New-SfEncryptionKeyFile -Path MyKeyFile.key

REMARKS

To see the examples, type: "Get-Help New-SfEncryptionKeyFile -Examples"
For more information, type: "Get-Help New-SfEncryptionKeyFile -Detailed"
For technical information, type: "Get-Help New-SfEncryptionKeyFile -Full"
For online help, type: "Get-Help New-SfEncryptionKeyFile -Online"

Remove-SfRecords

NAME

Remove-SfRecords

SYNOPSIS

Invokes Salesforce Data Loader with an DELETE or HARD_DELETE operation to delete records as given in a .csv file.

SYNTAX

Remove-SfRecords [-SfAuthToken] <Hashtable> [-Object] <String> [[-Path] <String>] [-MappingFile <String>] [-Bulk <String>] [-BatchSize <Int32>] [<CommonParameters>]

DESCRIPTION

PARAMETERS

-SfAuthToken <Hashtable>
    Hashmap as provided by Get-SfAuthToken command.
    
-Object <String>
    API name of the sObject/entity.
    
-Path <String>
    Path and filename of the input .csv file. 
    Needs to include the '.csv' extension.
    If no file name is provided, it will look for the default name "<Object>.csv" in the current directory.
    
-MappingFile <String>
    Path and filename of the '.sdl' mapping file. 
    If empty, a default mapping file will be created on the fly based on the column names in the input .csv file.
    
-Bulk <String>
    'Serial'            : Use BULK API in serial mode.
    'Parallel'          : Use BULK API in parallel mode.
    'SerialHardDelete'  : Use BULK API for a HARD_DELETE operation in serial mode.
    'ParallelHardDelete': Use BULK API for a HARD_DELETE operation in parallel mode.
    Default if not given is SOAP API.
    
-BatchSize <Int32>
    Default used for SOAP API: 200.
    Default used for BULK API: 2000.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

REMARKS

To see the examples, type: "Get-Help Remove-SfRecords -Examples"
For more information, type: "Get-Help Remove-SfRecords -Detailed"
For technical information, type: "Get-Help Remove-SfRecords -Full"
For online help, type: "Get-Help Remove-SfRecords -Online"

Update-SfRecords

ALIAS

sfupdate

NAME

Update-SfRecords

SYNOPSIS

Invokes Salesforce Data Loader with an UPDATE operation to create/update records from a '.csv' file.

SYNTAX

Update-SfRecords [-SfAuthToken] <Hashtable> [-Object] <String> [[-Path] <String>] [-MappingFile <String>] [-Bulk <String>] [-BatchSize <Int32>] [<CommonParameters>]

DESCRIPTION

Reads records from a .csv file and UPDATEs those in the org that is represented by the AuthToken.
The primary key always is the Record ID that needs to be provided in the .csv file.

If no filename is given, it is derived from the object to be imported: "<Object>.csv".
The format of the .csv file is defined as: UTF-8 encoding, without BOM, comma (,) as separator.
For more details see https://github.com/ubraig/sf-dataloader-cli/wiki/about-csv-files

If no mapping file ist given, a default mapping file will be derived from the column headers in the .csv file. 
See ConvertTo-SfMappingFile for details on this behaviour.

PARAMETERS

-SfAuthToken <Hashtable>
    Hashmap as provided by Get-SfAuthToken command.
    
-Object <String>
    API name of the sObject/entity.
    
-Path <String>
    Path and filename of the input .csv file. 
    Needs to include the '.csv' extension.
    If no file name is provided, it will look for the default name "<Object>.csv" in the current directory.
    
-MappingFile <String>
    Path and filename of the '.sdl' mapping file. 
    If empty, a default mapping file will be created on the fly based on the column names in the input .csv file.
    
-Bulk <String>
    'Serial'   : Use BULK API in serial mode.
    'Parallel' : Use BULK API in parallel mode.
    Default if not given is SOAP API.
    
-BatchSize <Int32>
    Default used for SOAP API: 200.
    Default used for BULK API: 2000.
    
<CommonParameters>
    This cmdlet supports the common parameters: Verbose, Debug,
    ErrorAction, ErrorVariable, WarningAction, WarningVariable,
    OutBuffer, PipelineVariable, and OutVariable. For more information, see
    about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216). 

REMARKS

To see the examples, type: "Get-Help Update-SfRecords -Examples"
For more information, type: "Get-Help Update-SfRecords -Detailed"
For technical information, type: "Get-Help Update-SfRecords -Full"
For online help, type: "Get-Help Update-SfRecords -Online"