Select SQL Table with PowerShell

      No Comments on Select SQL Table with PowerShell

I needed to query a database table with PowerShell and manipulate the results, preferably in a data table. I found querying this information was possible, but the results would be a static list and not very usable. I also did not wish to install SQL components to utilize other SQL Snapins, since I could use scripts on many different computers.

Thus, this function was created.

Example:

Example 1. Select all table contents.

Example of select specific columns and search criteria:

Example 2. Query SQL table with columns and criteria.



Download this script.

Alternatively you can save all of the SQL results into a PowerShell variable and then specify a WHERE clause:

Example 3. Save SQL results to PowerShell variable.

Leave a Reply

Your email address will not be published.