PowerShell Wrapper for Legacy Tools SqlCmd and SqlPackage
Executes SQLCMD
Invoke-LegacySqlCmd -InputFile <FileInfo> -ServerInstance <String> [-DatabaseCredential <PSCredential>]
[-WindowsCredential <PSCredential>] [-AccessToken <String>] [-DatabaseName <String>] [-ErrorLevel <Int32>]
[-ErrorSeverityLevel <Int32>] [-TerminateOnError] [-Timeout <Int32>] [-Variables <Hashtable>]
[<CommonParameters>]
Invoke-LegacySqlCmd -Command <String> -ServerInstance <String> [-DatabaseCredential <PSCredential>]
[-WindowsCredential <PSCredential>] [-AccessToken <String>] [-DatabaseName <String>] [-ErrorLevel <Int32>]
[-ErrorSeverityLevel <Int32>] [-TerminateOnError] [-Timeout <Int32>] [-Variables <Hashtable>]
[<CommonParameters>]
Wrapper tp the commandline tool SQLCMD. It provides parameter validation, output and error handling.
PS C:\>
Path to the executed SQL script file.
Type: FileInfo
Parameter Sets: File
Aliases: File
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Executed SQL script source.
Type: String
Parameter Sets: Command
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Name of the SQL Server Instance.
Type: String
Parameter Sets: (All)
Aliases: DataSource
Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Type: PSCredential
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Type: PSCredential
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Name fo the SQL Database.
Type: String
Parameter Sets: (All)
Aliases: Database
Required: False
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Minimum event severity to include in output.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
Minimum event severity to interpret as error.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 10
Accept pipeline input: False
Accept wildcard characters: False
Flag if a error must terminate the execution.
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Timeout in seconds for the execution.
Type: Int32
Parameter Sets: (All)
Aliases: ConnectionTimeout
Required: False
Position: Named
Default value: 0
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Values for variables, used in the script.
Type: Hashtable
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Check https://github.com/abbgrade/PsSqlClient and https://github.com/abbgrade/PsSmo if one of them already supports your use case. They provide better PowerShell integration.
https://docs.microsoft.com/de-de/sql/tools/sqlcmd-utility?view=sql-server-ver15