GithubHelp home page GithubHelp logo

jeffchulg / invoke-sqlcmd2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dataplat/invoke-sqlcmd2

0.0 1.0 0.0 130 KB

PowerShell module containing Invoke-SqlCmd2

License: MIT License

PowerShell 100.00%

invoke-sqlcmd2's Introduction

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:

  • Lightweight. No installation needed; just copy or download the file, copy the text, Install-Module, etc.
  • Simple parameterized queries. This was a source of exasperation in 2005. Over a decade later, Invoke-SqlCmd is still missing this.
  • Abstraction. Consider using and contributing to this, over writing your own .NET System.Data.SqlClient wrapper, or leaving a bunch of less friendly .NET code in your project

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:

  • Added pipeline support, with the option to append a ServerInstance column to keep track of your results:
    • Add ServerInstance column
  • Added the option to pass in a PSCredential instead of a plaintext password
    • Use PSCredential
  • Added PSObject output type to allow comparisons without odd [System.DBNull]::Value behavior:
    • Previously, many PowerShell comparisons resulted in errors:
      • GT Comparison Errors
    • With PSObject output, comparisons behave as expected:
      • GT Comparison Fix
    • Previously, testing for nonnull / null values did not work as expected:
      • NotNull Fails
    • With PSObject output, null values are excluded as expected
      • NotNull Fails Fix
    • Speed comparison between DataRow and PSObject output with 1854 rows, 84 columns:
      • Speed PSObject v Datarow

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?

  • @RamblingCookieMonster copied the code here to avoid the automated tweets for Poshcode.org submissions. He makes many small changes and didn't want to spam twitter : )
  • Since then, a number of contributions have come in. Separating this out into it's own repository simplifies and enables improved collaboration
  • Leaving this out of a larger module may be helpful for folks who simply want a lightweight function. Modules can depend on this or hard code a point-in-time copy as needed

invoke-sqlcmd2's People

Contributors

ramblingcookiemonster avatar potatoqualitee avatar niphlod avatar alevyinroc avatar mattmcnabb avatar shiyangqiu avatar jeffchulg avatar iguanaware avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.