Use the Database Engine cmdlets
Windows PowerShell cmdlets are single-function commands that typically have a verb-noun naming convention, such as Get-Help or Set-MachineName. The SQL Server provider for Windows PowerShell supplies cmdlets specific to SQL Server.
Database Engine cmdlets
SQL Server implements a small number of cmdlets for the Database Engine. These cmdlets are primarily used to run existing Transact-SQL scripts from new PowerShell scripts, evaluate policy-based management policies, and aid in specifying SQL Server identifiers in SQL Server Provider paths.
Most Windows PowerShell scripts work with the Database Engine by using the SQL Server PowerShell provider and the SQL Server manageability object models. For more information, see SQL Server PowerShell.
Get Cmdlet Help
In the Windows PowerShell environment, the Get-Help cmdlet provides help information for each cmdlet. Get-Help returns information such as the syntax, parameter definitions, input and output types, and a description of the action performed by the cmdlet. For more information, see Get Help SQL Server PowerShell.
Partial Parameter Names
You do not have to specify the entire name of a cmdlet parameter. You only have to specify enough of the name to uniquely separate it from the other parameters that are supported by the cmdlet. For example, these examples show three ways of specifying the Invoke-Sqlcmd -QueryTimeout parameter:
Invoke-Sqlcmd -Query "SELECT @@VERSION;" -QueryTimeout 3
Invoke-Sqlcmd -Query "SELECT @@VERSION;" -QueryTime 3
Invoke-Sqlcmd -Query "SELECT @@VERSION;" -QueryT 3
Database Engine cmdlet Tasks
Task Description | Topic |
---|---|
Describes using Invoke-Sqlcmd to run sqlcmd scripts or commands that contain Transact-SQL or XQuery statements. It can accept the sqlcmd input as either a character string input parameter, or as the name of a script file to open. | Invoke-Sqlcmd cmdlet |
Describes using Invoke-PolicyEvaluation to report whether a target set of SQL Server objects comply with the conditions that are defined in policy-based management policies. Optionally, the cmdlet can be used to reconfigure any settable options in the target objects that do not comply with the policy conditions. | Invoke-PolicyEvaluation cmdlet |
Describes using Encode-Sqlname and Decode-Sqlname to handle SQL Server identifiers that contain characters not supported in Windows PowerShell paths. |
Encode and Decode SQL Server Identifiers |
Describes using Convert-UrnToPath to convert a SQL Server Manageability Object Uniform Resource Name (URN) to the equivalent SQL Server Provider path. |
Convert URNs to SQL Server Provider Paths |
See Also
SQL Server PowerShell Provider
SQL Server PowerShell
Overview of PowerShell Cmdlets for AlwaysOn Availability Groups (SQL Server)