Powershell script to run query against many servers and send combined output as email


This powershell script is sample code to run query against multiple SQL Servers and export the combined output to Excel. This Excel file is later sent as email attachment using hotmail.

Related email thread: http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/thread/987d48c0-a82d-4424-8699-cdd0b2bc9c51

# This posting is provided “AS IS” with no warranties, and confers no rights.

Script can be also downloaded from emailResultsMultiServerQuery.ps1

About these ads

Developer @ SQL Server Team, Microsoft

Posted in SQL Power shell
2 comments on “Powershell script to run query against many servers and send combined output as email
  1. sqlfrndz says:

    Very Nice Script ! Helped me a lot .. Good Work..

  2. jaya1984 says:

    Hi Sethu. thanx for the script. how can i combine the following script to yours? i need the event list to be exported to an excel sheet and send out via email. i got the first part working. how can i combine both ? here’s the command i use -> Get-EventLog -LogName application | where { (($_.entrytype -eq “Error”) -or ($_.entrytype -eq “Warning”)) -and ($_.timewritten -ge (get-date).addDays(-1))} | export-csv “C:\scripts\appevents.csv

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: