power shell or batch file script for sql server

  • Could someone please provide me the powershell script for the below query.

    i have two text files,

    one file contains the list of SQL server's and another file have few sql queries.

    i am looking for a powershell script or windows batch file that pick up the server name from first file and run the sql commands which is in 2nd text file and keep the output in seperate text file.

  • A little research will go a long way on this one. Pretty basic PowerShell aspects:

    1: Reading files: Get-Content Cmdlet

    2: Executing queries: Getting Data out of SQL Server from Powershell[/url]

    3: Write to file: Add-Content Cmdlet



    Twitter: @SQLife
    Email: sqlsalt(at)outlook(dot)com

  • If you have specific questions, we can help, but spend a little time on those articles and you should be able to put something together.

  • I am new to powershell.It will be great if you provide the powershell script of the query. I tried to frame by using your suggestions, but somehow it is not working.

  • Did you get any of the scripts from Chad's article working? Those show you how to connect to SQL Server and run something.

    From there, you might look over this one as well: http://www.sqlservercentral.com/articles/powershell/76561/

    I don't have an exact script that does what you want, and I'm not going to spend time building one when it doesn't appear you've done anything. We are happy to help with specific questions, but we aren't here to do your work. "somehow it is not working" doesn't imply you did anything. Showing the specific error, or explaining the results from your efforts lead to specific questions. Why isn't my loop working, or why can't I connect to SQL Server. Those we help with.

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

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