Home Forums Programming Powershell Good current Powershell/SQL tutorials? RE: Good current Powershell/SQL tutorials?

  • 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