Home Forums Programming Powershell Powershell script being run as SQL agent job RE: Powershell script being run as SQL agent job

  • ALZDBA (7/10/2013)


    with regards to your Powershell script:

    do you actually use an xlsx template to fill out with your data?

    do you actually use any excel functionallity at all ?

    if not: just change the powershell to save your data as CSV !

    pro:

    - you don't need to have office parts installed on your sever

    - opened by a client that has excel installed, the csv file will be opened by it.

    con:

    - when opened by excel, it will not format the columns by default ( meaning column width, color, font,...)

    use e.g.

    # export data to csv sorted by ServerName, DbName, Name in ascending order

    $drAllRslt | Sort-Object ServerName, DbName, Name | export-csv -path "D:\SQLAgentResults\Reslut123.csv" -NoTypeInformation

    Johan

    Thanks for that. I am still trying to learn powershell. Could I post the code I am using and then could you show me where I need to change it in order for it work with your suggested changes ?