SQL Requests & Powershell

SQL Requests & Powershell

roualin powershell_2 SQL Requests & PowershellIt could be really hard to find something interesting on the web when we encountered a trouble in Powershell.

After a long search, I found it ! So, let’s share..

A request in SQL using powershell can be send using .Net Frameword.

You should have in mind that SQL request through powershell are exactly the same like standard SQL requests !

Here is an example with a simple Select :

$conec = “server=;database=;Integrated Security=sspi”
$da = new-object System.Data.SqlClient.SqlDataAdapter ($cmd, $conec)
$dt = new-object System.Data.DataTable

The “Integrated Security” allow to use Windows Authentication, so the account used to launch the powershell script should have rights on the Database !

The SQL request’s results are contained into the “$dt” variable.

So… Let’s “play” now !

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site