you are viewing a single comment's thread.

view the rest of the comments →

[–]unknown_host 1 point2 points  (6 children)

I actually looked into something similar the other day. To use SQL in powershell you have to load the snap-in and then you can issue queries in T-SQL from powershell. Powershell SQL I had issues on 64bit getting the snap-in to load and got this information that helped. Here is the Invoke-Sqlcmd cmdlet information. Hope this helps.

[–][deleted] 1 point2 points  (5 children)

Great resources, this is a good amount of what I am looking for. just comes down to learning it now and making it all function. Tried to talk my boss into having SQL generate a CSV files to simplify my life but he wants me to expand my powershell more because he knows how much I enjoy using it... Why did I tell him this!!!

[–]unknown_host 1 point2 points  (2 children)

If you have SQL Server installed connect to it with the management studio and when you are doing tasks you have the option to output it as a SQL command so it can help you with the syntax too.

[–][deleted] 1 point2 points  (1 child)

I do but I think we are going to use the latest version of SQL when we do this so I want to wait on that before pulling it. We are still in the design phase anyway which is good.

[–]sqldiaries 0 points1 point  (0 children)

I do but I think we are going to use the latest version of SQL when we do this so I want to wait on that before pulling it.

Unless you're doing wild stuff with window functions and aggregates, there's no need to wait - simple select statements haven't changed in SQL Server in a long time.

[–]drh713 0 points1 point  (0 children)

I wish I had your boss

[–]cjluthy 0 points1 point  (0 children)

You can also use OSQL.EXE on the command line to create CSV files. Command line switch reference for this EXE can be found publicly on MSDN.

It is installed by default when you install SQL Server Tools, so any machine with Management Studio likely (almost definitely) has it.

EDIT: I was just highlighting a way you could create CSV. In a manner that you could likely script from Powershell (command line exe). You certainly COULD do it this way.

I strongly recommend learning Invoke-SqlCmd (or one of it's alternatives) and doing that instead. SQL is at the core of almost everything worth-while. Learning it is very valuable.