SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Good current Powershell/SQL tutorials?


Good current Powershell/SQL tutorials?

Author
Message
sqldriver
sqldriver
SSC Eights!
SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)

Group: General Forum Members
Points: 978 Visits: 2518
Hi,

Trying to follow older tutorials is pretty frustrating. It seems like a lot of the syntax results in errors, or in some cases is a few versions behind and there are probably better ways to do things at this point.

My main goal is getting PS to query SQL and write formatted Excel files of the results. I realize that I'm probably not going to get both in one shot, but if anyone has found a good read in either area, I'd really appreciate any suggestions. The Stairways that are posted on this site even seem a couple versions old.

Thanks
Gary Varga
Gary Varga
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16549 Visits: 6534
Perhaps it would help if you broke down what experience you have and what elements you need help with. Also, you talk about versions yet do not specify which ones you yourself are using (I could be interpreted as sounding a bit aggressive but I am just trying to get you clarity and then a resolution for you).

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
sqldriver
sqldriver
SSC Eights!
SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)

Group: General Forum Members
Points: 978 Visits: 2518
No, I should have been a bit more clear. This is the version I'm using:

Name Value
---- -----
PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.34003
BuildVersion 6.3.9600.16394
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2

I've played along with PS following examples, but nothing beyond beginner, I don't think. I have it successfully querying a server with this code that I found and re-used, though I don't entirely understand from $DataSet down:


$SqlQuery = "SELECT project_SPSS,ID_project,project_ID_Server FROM ProjectList where project_status=3 and project_ID_Server in(7,11) order by project_ID_Server"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=PHSQL; Database=Utilities; Trusted_Connection = yes"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$nSet = $SqlAdapter.Fill($DataSet)
$OutputTable = $DataSet.Tables[0]
$SqlConnection.Close();
$OutputTable | ft -autosize



I'm guessing I could stick an object out on there to have it pipe to an Excel file (not a .csv), so I'm looking for anything that may walk me through the finer points of piping query results out, and performing some formatting on them, like bolding header rows, adding borders, etc.

Thanks
Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40274 Visits: 32663
For just learning PowerShell, I'd suggest Don Jones book, PowerShell in a Month of Lunches. It'll give you most of what you need to learn it.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
sqldriver
sqldriver
SSC Eights!
SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)SSC Eights! (978 reputation)

Group: General Forum Members
Points: 978 Visits: 2518
Thanks, Grant. I'll add this to my current reading rotation.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search