Invoke-SqlScript

Runs a SQL script file as part of a migration.

Syntax

Invoke-SqlScript -Path <String> [-CommandTimeout <UInt32>] [<CommonParameters>]
Invoke-SqlScript -Path <String> -AsScalar [-CommandTimeout <UInt32>] [<CommonParameters>]
Invoke-SqlScript -Path <String> -NonQuery [-CommandTimeout <UInt32>] [<CommonParameters>]

Description

The SQL script is split on GO statements, which must be by themselves on a line, e.g.

select * from sys.tables
GO

select * from sys.views
GO

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String

The path to the SQL script to execute.

true false
AsScalar SwitchParameter true false False
NonQuery SwitchParameter true false False
CommandTimeout UInt32

The time in seconds to wait for the command to execute. The default is 30 seconds.

false false 30