Sethu's blog

January 11, 2012

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

Filed under: SQL Power shell — sethusrinivasan @ 2:26 pm

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

2 Comments »

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

    Comment by sqlfrndz — June 14, 2012 @ 2:10 pm | Reply

  2. 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

    Comment by jaya1984 — October 9, 2012 @ 9:16 pm | Reply


RSS feed for comments on this post. TrackBack URI

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 )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: