Skip to content

Instantly share code, notes, and snippets.

@naraga
Created July 27, 2012 22:07
Show Gist options
  • Save naraga/3190703 to your computer and use it in GitHub Desktop.
Save naraga/3190703 to your computer and use it in GitHub Desktop.
Executes MSSQL query and pushes output (as PSCustomObject objects) into pipe
function SelectFrom-Mssql([string] $selectQuery)
{
. sqlcmd -S "(local)" -d `"mydb`" `-Q "SET NOCOUNT ON $selectQuery" -s "|" -W |
ConvertFrom-CSV -Delimiter "|" |
select -skip 1
}
SelectFrom-Mssql "exec sp_who"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment