header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

MS SQL 2005 - Help with PowerShell Interface
Last Post 05 May 2008 08:18 PM by halr9000. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
05 May 2008 04:06 PM  

I have another project running (which is work related) along side my Eliza project (which is not work related).

Does anyone have tips or pointers on how to interface a PowerShell script with a MS SQL 2005 database?  Where should I look first?

My blog: http://blogs.powershellcentral.com/kscriss/
kscrissUser is Offline
Basic Member
Basic Member
Posts:119

--
05 May 2008 04:41 PM  

This article looks helpfull. Hope it works with the standard release of PowerShell.

http://www.pluralsight.com/blogs/dan/archive/2006/10/28/41337.aspx  

My blog: http://blogs.powershellcentral.com/kscriss/
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
05 May 2008 08:13 PM  
There's a bunch of examples out there. You need to first pick a connection method. If you have the SQL native client installed, that's a good way to go. I don't know SQL Server as well as I'd like, so I can't say what is the "best", but there are several others. They all have one thing in common and that's the concept of a connection string. You can find out how to make for your case here: http://www.connectionstrings.com/

Also check out BSonPosh's Google custom search engine, search for sql there.

Here's an example using System.Data.SqlClient.SqlConnection (that I ripped off from channel 9 wiki).

function sqlConnect ([string]$connString)

{

$sqlConn = new-object System.Data.SqlClient.SqlConnection;
$sqlConn.ConnectionString = $connString;
$sqlConn.Open();
$sqlConn.Close();

}
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
halr9000User is Offline
PowerShell MVP, Site Admin
Basic Member
Basic Member
Posts:334
Avatar

--
05 May 2008 08:18 PM  
Just scanned that link, wow that's an awesome article, wish I'd seen it back in 2006 when it was written. :) Yes, everything in there applies perfectly to V1 of PowerShell. I didn't even see any old MSH code. You'll notice he uses the same .NET object to do the queries as I pasted above.
Community Director, PowerShellCommunity.org
Co-host, PowerScripting Podcast
Author, TechProsaic
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer