Skip to content

Instantly share code, notes, and snippets.

@davops
Created April 21, 2016 19:38
Show Gist options
  • Save davops/ae183ba614f0a2f7dc52207b9d269ab7 to your computer and use it in GitHub Desktop.
Save davops/ae183ba614f0a2f7dc52207b9d269ab7 to your computer and use it in GitHub Desktop.
Run SQL queries remotely in PowerShell v2
$thisPsSession = New-PSSession "Server1"
Invoke-Command -Session $thisPsSession -ScriptBlock {
sqlcmd.exe -q "SELECT yourcolumn FROM yourdatabase"
}
Remove-PSSession $thisPsSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment