powershellinvoke-sqlcmd

Invoke-SqlCmd vs SqlCmd


I have to tried to find the source code for Invoke-SqlCmd, but to no luck. My question is: Does Invoke-SqlCmd use sqlcmd.exe behind the scenes?

Additionally, are there any SQL Server commands available for PowerShell Core on Linux?


Solution

  • To install the SqlServer module on PowerShell Core in Linux simply install it.

    Install-Module -Name SqlServer
    

    More information: Manage SQL Server on Linux with PowerShell Core

    Also: cmdlets currently available in PowerShell Core

    As the cmdlets currently available in PowerShell Core also include Invoke-Sqlcmd and that they need to work cross-platform, this indicates that it does not use sqlcmd.exe behind the scenes. Additionally, the documentation for Invoke-Sql state:

    Runs a script containing statements supported by the SQL Server SQLCMD utility.

    So it "fakes" the syntax for backwards compatibility and to upgrade existing scripts. But there are a few specific commands that are not supported, which also is an indicator that it is not running sqlcmd.exe in the background.