Groups > Microsoft > Windows PowerShell > Re: List out SQL Jobs?




List out SQL Jobs?

List out SQL Jobs?
Tue, 15 Apr 2008 10:42:01 -070
Is there a way to hook into Enterpise Manager and list out all sql jobs 
Post Reply
RE: List out SQL Jobs?
Tue, 15 Apr 2008 11:00:01 -070
You can access the jobs through SMO.  I don't have an example available at 
the moment.  I  try and post one soon


-- 
Richard Siddaway
All scripts are supplied "as is" and with no warranty 
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"akcorr" wrote:

> Is there a way to hook into Enterpise Manager and list out all sql jobs 
Post Reply
Re: List out SQL Jobs?
Tue, 15 Apr 2008 11:51:22 -070
On Apr 15, 1:42 pm, akcorr <akc...@discussions.microsoft.com> wrote:
> Is there a way to hook into Enterpise Manager and list out all sql jobs
> and/or their runtimes?

Try this as a start, replace "server1","server2" with you
list of
servers(instances) to check
#
################################################################################
#######
#
#	Author: 	Stephen Merkel
#	Date:		01/09/2007
#	Script: 	info.ps1
#	Purpose:	Shows enabled jobs whose last run outcome is Failed
#
#
#	Parameters: 	server name(s)
#
################################################################################
########


[void]
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionI
nfo");
[void]
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum&quo
t;);
[void]
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo");


$smo = "Microsoft.SqlServer.Management.Smo."

if ( $Args.length -eq 0) {$a=("server1","server2")
}
else {$a=$args}
get-date -format g

foreach ($el in $a) {
	$srv = new-object ($smo + 'server') $el
	$el.toupper()

	$srv.jobserver.jobs | where-object {$_.lastrunoutcome -eq "Failed" -
and $_.isenabled -eq $TRUE} | format-table
name,lastrunoutcome,lastrundate -autosize

	
{"-------------------------------------------------------------------------
-----"}
Post Reply
about | contact