Giter Club home page Giter Club logo

powershellrcm's Introduction

PowerShell

Various PowerShell functions and scripts

Instructions

These files contain functions. For example, Invoke-Sqlcmd2.ps1 contains the Invoke-Sqlcmd2 function.

#Download and unblock the file(s).
#Dot source the file(s) as appropriate.
. "\\Path\To\Invoke-Sqlcmd2"

#Use the functions
Get-Help Invoke-Sqlcmd2 -Full
Invoke-Sqlcmd2 -ServerInstance MyServer\MyInstance -Query "SELECT ServerName, VCNumCPU FROM tblServerInfo" -As PSObject -Credential $cred | ?{$_.VCNumCPU -gt 8}

Invoke-Sqlcmd2

I'm a fan of Invoke-Sqlcmd2. Props to Chad Miller and the other contributors for a fantastic function. I'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.

You clearly don't know SQL. Why are you working on this function?

I absolutely do not know SQL. If I'm doing something wrong please let me know!

I have a number of projects at work that involve PowerShell wrappers for SQL queries. Invoke-Sqlcmd2 has been my go-to command for this - now that I'm spending more time with it, I plan to add some functionality.

Why is Invoke-Sqlcmd2 here?

I copied the code here to avoid the automated tweets for Poshcode.org submissions. I make many small changes and didn't want to spam twitter : )

TechNet Galleries Contributions

I've copied and will continue to update my TechNet gallery contributions within this repository.

Help!

Would love contributors, suggestions, feedback, and other help!

powershellrcm's People

Contributors

ramblingcookiemonster 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.