Home

Awesome

Invoke-SqlCmd2

Invoke-SqlCmd2 is a compact function to query SQL Server without other dependencies. It was originally written by Chad Miller, with numerous community contributions along the way.

There are several key benefits to using Invoke-SqlCmd2:

Pull requests and other contributions would be welcome!

Instructions

# One time setup
    # Download the repository
    # Unblock the zip
    # Extract the Invoke-SqlCmd2 folder to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\)

    # Simple alternative, if you have PowerShell 5, or the PowerShellGet module:
        Install-Module Invoke-SqlCmd2

# Import the module.
    Import-Module Invoke-SqlCmd2    #Alternatively, Import-Module \\Path\To\Invoke-SqlCmd2

# Get help
    Get-Help Invoke-SqlCmd2 -Full

Features

Props to Chad Miller and the other contributors for a fantastic function. We've added a few features with much help from others:

That DBNull behavior is strange! Why doesn't it behave as expected?

I agree. PowerShell does a lot of work under the covers to provide behavior a non-developer might expect. From my perspective, PowerShell should handle [System.DBNull]::Value like it does Null. Please vote up this Microsoft Connect suggestion if you agree!

Major thanks to Dave Wyatt for providing the C# code that produces the PSObject output type as a workaround for this.

Why is Invoke-Sqlcmd2 here?