Name
Export-QueryResult — Exports the query result to the file or the database.
Synopsis
Exports the query result to the file or the database.
Syntax
Export-QueryResult [-QueryRun <QueryRun>] [-ExportFormat <String>]
[-ConnectionStringOrPath <String>] [-TableOrFileName <String>] [-AppServerNameAndPort <String>] [-BindingType <String>] [-PipingEnabled <Boolean>]
Authorization requirements
You must have the following CCS tasks to use the cmdlet:
You must have the permissions on the following folders to use the cmdlet:
Queries folder
Queries subfolder
Description
The Export-QueryResult cmdlet exports the query result to a file or a database based on the input parameters.
Parameters
The following table describes the parameters that the Export-QueryResult cmdlet requires:
Table: Export-QueryResult - parameters
Switch Name |
Switch Type |
Data Type |
Supports piping input? Yes/No |
Description |
AppServerNameAndPort |
Mandatory |
String |
No |
The name of the application server and the port matching the binding type. The value for the parameter can be specified from the PowerShell variable as: $AppServerNameAndPort="<AppServerName/IP> : <Port Number Corresponding To Binding Type Set>" Once specified , you need not specify the value again for every cmdlet in that session. |
Binding Type |
Optional |
String |
No |
A valid binding type. The default binding type is NETTCP. You can specify binding types such as HTTP, HTTPS, NETTCP. The value for the parameter can be specified from the PowerShell variable as: $BindingType="<NETTCP or HTTP or HTTPS>" Once specified , you need not specify the value again for every cmdlet in that session. |
QueryRun |
Mandatory |
Asset |
Yes |
The QueryRun object for which the result needs to be exported. You can get the QueryRun object from Get-QueryRuns cmdet. |
ExportFormat |
Mandatory |
String |
Yes |
The format to which the results need to be exported. The supported formats are CSV, XML, DOC, XLS, PDF and SQL. |
ConnectionString OrPath |
Mandatory |
String |
No |
Specifies the directory path or database connection string to use for saving the exported results. You must provide a share path for this parameter. For instance, \\Machine\Exports |
TableOrFileName |
Mandatory |
String |
No |
The file or table name to use for saving the exported results. |
PipingEnabled |
Optional |
Boolean |
Yes |
The default value of this parameter is False. Set to True if output of the cmdlet required as piping inputs. |
Inputs
The Export-QueryResult cmdlet takes the QueryRun object, export format, export path or connection string and file or table name as input.
Outputs
The Export-QueryResult cmdlet did not return any output. As a result of the successful execution of the cmdlet, the associations are removed from the business asset.
The QueryRun object contains the following information:
Table: QueryRun
Field Name |
Data Type |
Description |
RunID |
Guid |
The unique identifier of the query run. |
RunStatus |
String |
The status of the query run. |
StartDate |
DateTime |
The start date and time for the query run. |
EndDate |
DateTime |
The end date and time for the query run. |
RunDuration |
String |
The duration for which the run was executing. |
ResultReceived |
long |
The number of result files that were received for the run. |
ErrorCount |
long |
The number of errors that were received for the run. |
Notes
You can set AppServerNameAndPort variable only once and reuse it till the session is closed.
You can set BindingType variable only once and reuse it till the session is closed.
ExportFormat parameter is a string that can take the values of the formats that are supported for export. The valid inputs of this parameter are CSV, XML, DOC, XLS, PDF, SQL ConnectionStringOrPath parameter value specifies the directory path or database connection string to export the data TableOrFileName the file or table name for the exported dataset
The ExtensionData property should be ignored, if present in the output. It is a WCF specific property that is required for making the data contract forward-compatible and for versioning process.
Example 1
C:\PS>C:\PS> $query = Search-Query -QueryName "WindowsFile" -PipingEnabled $true
C:\PS> $queryrun = Get-QueryRuns -Query $query[0] -PipingEnabled $true
C:\PS> Export-QueryResult -QueryRun $queryrun[0] -ExportFormat "xml" -ConnectionStringOrPath "\\Machine1\Exports" -TableOrFileName "cmdlettest.xml"
Description: The cmdlet exports the result for the first run for the query having the name WindowsFile to a file named cmdlettest.xml in the folder \\Machine1\Exports
Thanks for your feedback. Let us know if you have additional comments below. (requires login)