Solved

how can i monitor scheduled tasks on remote windows servers?

Posted on 2014-09-11
2
326 Views
Last Modified: 2014-09-29
Hello Experts.

how can I monitor scheduled tasks on remote windows servers?

I have a number of requirements as to the data I need to yield

Scheduled tasks where DaysOfTheWeek = Yesterday
Date/time stamp from last schedule execution
Status/Exit code from last schedule execution

Thank you for your help
0
Comment
Question by:Chris Portsmouth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Joshua Grantom earned 500 total points
ID: 40317107
I think you can give this a shot. I have modified it to pull only Name of Task, Computer Name, Last Run Result and Last Run Time but only for yesterday.

The function is by Twon of An http://community.spiceworks.com/scripts/show/2094-get-scheduled-tasks-from-a-computer-remote-or-local

<#
.SYNOPSIS
	Get-ScheduledTasks will retrieve a list of scheduled tasks.
.DESCRIPTION
	Get-ScheduledTasks gets an exhaustive list of all scheduled tasks on the specified computer. It accomplishes this by created a schedule object and having that query the schedule service of the desired computer.
.PARAMETER ComputerName
	The name of the computer that you would like to gather information about. Defaults to the localhost.
.PARAMETER RootOnly
	When specified, the cmdlet will retrieve just the top level tasks. Usually the user specified ones.
.EXAMPLE
	Get-ScheduledTasks DC1 -RootOnly
	
	Actions        : WScript.exe C:\scripts\MyScript.vbs
	Path           : \Run My Script
	Enabled        : True
	Triggers       : CalendarTrigger
	Description    : The Scheduled task that runs my script.
	Author         : DOMAIN\User
	Name           : Run My Script
	NextRunTime    : 9/1/2013 3:00:00 AM
	LastRunTime    : 8/1/2013 3:00:00 AM
	LastTaskResult : 267014
.EXAMPLE
	Get-ADComputer -filter 'name -like "Workstation1*"' | select name | Get-ScheduledTasks
	
	This will return a long list of scheduled tasks from every computer in AD that meets the filter.
.INPUTS
.OUTPUTS
	Custom PSObject with properties: ComputerName,Actions,Path,Enabled,Triggers,Description,Author,Name,NextRunTime,LastRunTime,LastTaskResult
.NOTES
	Author: Twon of An
.LINK
	Schedule.Service
#>
Function Get-ScheduledTasks
{
	Param
	(
		[Alias("Computer","ComputerName")]
		[Parameter(Position=1,ValuefromPipeline=$true,ValuefromPipelineByPropertyName=$true)]
		[string[]]$Name = $env:COMPUTERNAME
		,
		[switch]$RootOnly = $false
	)
	Begin
	{
		$tasks = @()
		$schedule = New-Object -ComObject "Schedule.Service"
	}
	Process
	{
		Function Get-Tasks
		{
			Param($path)
			$out = @()
			$schedule.GetFolder($path).GetTasks(0) | % {
				$xml = [xml]$_.xml
				$out += New-Object psobject -Property @{
					"ComputerName" = $Computer
					"Name" = $_.Name
					"Path" = $_.Path
					"LastRunTime" = $_.LastRunTime
					"NextRunTime" = $_.NextRunTime
					"Actions" = ($xml.Task.Actions.Exec | % { "$($_.Command) $($_.Arguments)" }) -join "`n"
					"Triggers" = $(If($xml.task.triggers){ForEach($task in ($xml.task.triggers | gm | Where{$_.membertype -eq "Property"})){$xml.task.triggers.$($task.name)}})
					"Enabled" = $xml.task.settings.enabled
					"Author" = $xml.task.RegistrationInfo.Author
					"Description" = $xml.task.registrationInfo.Description
					"LastTaskResult" = $_.LastTaskResult
					"RunAs" = $xml.task.principals.principal.userid
				}
			}
			If(!$RootOnly)
			{
				$schedule.GetFolder($path).GetFolders(0) | % {
					$out += get-Tasks($_.Path)
				}
			}
			$out
		}
		ForEach($Computer in $Name)
		{
			If(Test-Connection $computer -count 1 -quiet)
			{
                Write-Error "`n$Computer`n"
				$schedule.connect($Computer)
				$tasks += Get-Tasks "\"
			}
			Else
			{
				Write-Error "Cannot connect to $Computer. Please check it's network connectivity."
				Break
			}
			$tasks
		}
	}
	End
	{
		[System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null
		Remove-Variable schedule
	}
}

# Sets the location for the Csv Report
$CsvReport = "C:\ScheduledTasksReport.csv"


(Get-ADComputer -Filter {Enabled -eq $True -and Operatingsystem -like "*server*"}).name | Get-ScheduledTasks -RootOnly | Select-Object Name,ComputerName,LastRunTime,LastTaskResult | Where-Object { ($_.LastRunTime -ge (get-date).AddDays(-1)) }| Export-CSV $CsvReport -NoTypeInformation

Open in new window

0
 

Author Closing Comment

by:Chris Portsmouth
ID: 40349673
solution provided solved my issue
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question