Good current Powershell/SQL tutorials?

  • 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

  • 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!!!

  • 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

  • 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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks, Grant. I'll add this to my current reading rotation.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply