< Back

Invoke-DataQuery

Tue Jan 14, 2020 1:25 am

NAME Invoke-DataQuery



SYNOPSIS

Executes a database query.





SYNTAX

Invoke-DataQuery [-FileOrName] <string> [-Query] <string> [[-Parameters] <object>] [[-Timeout] <int>] [-AsDataRow

<SwitchParameter>] [-AsDataTable <SwitchParameter>] [-PreserveDbNull <SwitchParameter>] [-ShowRecordsAffected

<SwitchParameter>] [<CommonParameters>]



Invoke-DataQuery [-Connection] <DbConnection> [-Query] <string> [[-Parameters] <object>] [[-Timeout] <int>]

[-AsDataRow <SwitchParameter>] [-AsDataTable <SwitchParameter>] [-PreserveDbNull <SwitchParameter>]

[-ShowRecordsAffected <SwitchParameter>] [<CommonParameters>]





DESCRIPTION

The Invoke-DataQuery cmdlet executes a query to a database.



Despite its name, this cmdlet can execute any SQL statement, including INSERT, DELETE and CREATE. When such a

statement is executed, no result will return. By specifying the -ShowRecordsAffected parameter, you can get the

number of records affected by the statement. You can always obtain the same value by the Get-DataQueryResult

cmdlet.



By default, the DBNull values in the result data set are replaced with normal null values, and the results are

returned as a stream of PSObject values. You can change this behavior by the -PreserveDbNull and -AsDataRows

switch parameters.





PARAMETERS

-FileOrName <string>

A database file name or a connection string name.



Required? true

Position? 0

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Connection <DbConnection>

A database connection.



Required? true

Position? 0

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Query <string>

A query statement.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Parameters <object>

Query parameters.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Timeout <int>

A query timeout in seconds.



Required? false

Position? 3

Default value 0

Accept pipeline input? false

Accept wildcard characters? false



-ShowRecordsAffected <SwitchParameter>

Specifies whether the number of records affected by the query should be returned.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-PreserveDbNull <SwitchParameter>

Stops replacing the DBNull values in the results with normal null values.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-AsDataRow <SwitchParameter>

Indicates to return the result data set as System.Data.DataRow instead of PSObject.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-AsDataTable <SwitchParameter>

Indicates to return the result data set as System.Data.DataTable instead of an array of PSObjects.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<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).



INPUTS



OUTPUTS

System.Data.DataRow



System.Data.DataTable



System.Management.Automation.PSObject







RELATED LINKS