Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Good current Powershell/SQL tutorials? Expand / Collapse
Author
Message
Posted Wednesday, October 23, 2013 3:27 PM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 3:36 PM
Points: 431, Visits: 1,744
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

Post #1507835
Posted Thursday, October 24, 2013 2:14 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 7:16 AM
Points: 5,423, Visits: 3,155
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!!!
Post #1507914
Posted Thursday, October 24, 2013 8:05 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 3:36 PM
Points: 431, Visits: 1,744
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

Post #1508061
Posted Thursday, October 24, 2013 8:05 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 7:03 AM
Points: 15,738, Visits: 28,146
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1508062
Posted Thursday, October 24, 2013 8:33 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: 2 days ago @ 3:36 PM
Points: 431, Visits: 1,744
Thanks, Grant. I'll add this to my current reading rotation.

Post #1508090
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse