Calling SQL From Powershell

With SQL Server 2008 it became a lot easier! Just register the SQL SQL Server snapins and then invoke SQL Commands.

add-pssnapin sqlserverprovidersnapin100
add-pssnapin sqlservercmdletsnapin100

invoke-sqlcmd -query "select * from TestData.dbo.Addresses"

The names of the snappins are a little obtuse. I created a script in my C:\powershellscripts\ folder wrapping them (sqlsnap.ps1).

Advertisements
This entry was posted in .Net and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s