This project is read-only.

Synopsis

Invokes Sql Statement and returns data.

Syntax

Invoke-SqlQuery [-Query] <String> [[-Parameters] <Hashtable>] [-ConnectionName <String>] [-Stream] [-CommandTimeout <Int32>] [<CommonParameters>]

Description

Invokes Sql statement and returns data. This can handle multiple result sets (if underlying provider supports it). If there are multiple result sets, the output is datatables, otherwise datarows.
If the ‘Stream’ switch is used, only the first result set is returned and the output is PSObject represented a row.

Parameters

-Query <String>

SQL statement to run.

Required? True
Position? 1
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-Parameters <Hashtable>

Parameters required by the query. Key matches the parameter name, Value is the value of the parameter.

Required? False
Position? 2
Default value  
Accept pipeline input? true (ByValue)
Accept wildcard characters? False

-ConnectionName <String>

User defined name for connection.

Required? False
Position? named
Default value Default
Accept pipeline input? false
Accept wildcard characters? False

-Stream <SwitchParameter>

Uses a datareader to stream PSObject representing the results of the query to the pipeline, results will appear as soon as the connection begins returning data.

Required? False
Position? named
Default value  
Accept pipeline input? false
Accept wildcard characters? False

-CommandTimeout <Int32>

The timeout for this SQL statement, defaults to the command timeout for the SqlConnection.

Required? False
Position? named
Default value -1
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 (http://go.microsoft.com/fwlink/?LinkID=113216).

Examples

Example 1

PS C:\> Invoke-SqlQuery -Query "Select 1 + @Val AS myCalc" -Parameters @{Val=10}
myCalc
------
    11

Invokes a sql statement with a parameter.

Last edited Jun 23, 2015 at 2:30 PM by mastertook, version 2